#include <iostream> #include <string> using namespace std; int main() { int T; cin >> T; while (T) { int K; cin >> K; int p; int q; int path[100]; int count = 0; string s; getline(cin, s); string delim = "/"; string token = s.substr(0, s.find(delim)); s.erase(0, s.find(delim) + delim.length()); p = stoi(token, 0, 10); q = stoi(s, 0, 10); int res_q; int res_p; if (q == 1) { if (p == 1) { res_q = 2; res_p = 1; } else { res_q = p+1; res_p = 1; } cout << K << " " << res_p << "/" << res_q << endl; } else { while (p > q) { path[count] = 0; count++; p = p-q; } // path[count] = 1; q = q-p; p = p+q; while(count > 0) { q = q+p; count--; } res_p = p; res_q = q; cout << K << " " << res_p << "/" << res_q << endl; } T--; } return 0; }