#include #include #include #include #include #include #include #include #include #define ll long long #ifndef ONLINE_JUDGE #define gc getchar #else #define gc getchar_unlocked #endif #ifndef ONLINE_JUDGE #define pc putchar #else #define pc putchar_unlocked #endif using namespace std; int read_int() { int f=0; char c = gc(); if(c=='-') f=1; while(c<'0' || c>'9') c = gc(); int ret = 0; while(c>='0' && c<='9') { ret = 10 * ret + c - 48; c = gc(); } if(!f) return ret; else return (-ret); } void write_int(int n) { int N = n, rev, count = 0,g=0; if(N<0) { g=1; N=-N; } rev = N; if (N == 0) { pc('0'); pc('\n'); return ; } while ((rev % 10) == 0) { count++; rev /= 10; } rev = 0; while (N != 0) { rev = (rev<<3) + (rev<<1) + N % 10; N /= 10; } if(g==1) pc('-'); while (rev != 0) { pc(rev % 10 + '0'); rev /= 10; } while (count--) pc('0'); pc(' '); } int main() { //freopen("small.txt","r",stdin); //freopen("Obig2.txt","w",stdout); int Q=read_int(); while(Q--) { int N=read_int(); int T=read_int(); int X=read_int(); int Y=read_int(); int Z=read_int(); int a=Y-X; int b=Z-Y; int A,B=2*N+1; if(T==2||T==4) A=B-2*Y; else if(T==1) { if(a!=b) A=Z; else A=B-Z; } else { if(a!=b) A=X; else A=B-X; } int gcd=__gcd(A,B); A=A/gcd; B=B/gcd; write_int(A); write_int(B); cout<<"\n"; } }