#include using namespace std; using ll = long long; const ll INF = 1LL << 60; #define all(a) begin(a), end(a) #define sz(a) ssize(a) template bool chmin(T& a, U b) { return a > b ? a = b, 1 : 0; } template bool chmax(T& a, U b) { return a < b ? a = b, 1 : 0; } using pll = pair; using vpll = vector; using vll = vector; using vvll = vector; using lll = __int128_t; istream &operator>>(istream &is, lll& v) { string s; cin >> s; v = 0; for(char c:s){if(isdigit(c))v=v*10+(c-'0');} if(s[0]=='-') v*=-1; return is; } ostream &operator<<(ostream &os, lll v) { if(!ostream::sentry(os)) return os; char buf[64]; char *d=end(buf); lll tmp = (v<0?-v:v); do{d--;*d=char(tmp%10+'0');tmp/=10;}while(tmp); if(v<0) {d--;*d = '-';} int len=end(buf)-d; if(os.rdbuf()->sputn(d, len)!=len){os.setstate(ios_base::badbit);} return os; } #define _O(_1, _2, _3, n, ...) n #define _r1(i, n) for(ll i = 0; i < (ll)(n); i++) #define _r2(i, l, r) for(ll i = (ll)(l); i < (ll)(r); i++) #define rep(...) _O(__VA_ARGS__, _r2, _r1)(__VA_ARGS__) #define _rr1(i, n) for(ll i = (ll)(n) - 1; i >= 0; i--) #define _rr2(i, l, r) for(ll i = (ll)(r) - 1; i >= (ll)(l); i--) #define rrep(...) _O(__VA_ARGS__, _rr2, _rr1)(__VA_ARGS__) template ostream& operator<<(ostream& o, const vector& v) { ll i = 0; for(auto& x : v) o << (i++ ? " " : "") << x; return o; } template void out(const H& h, const T&... t) { cout << h; ((cout << " " << t), ...); cout << endl; } int main(){ ll _; cin >> _; while(_--){ lll n,x,y,a,b; cin >> n >> x >> y >> a >> b; if(x+y < 0 && x+y+n*a < 0) { out(x+a*n,y); continue; } if(x+y >= 0 && x+y-n*b >= 0) { out(x,y-b*n); continue; } if(x+y >= 0){ lll k = (x+y)/b+1; n -= k; y -= b*k; }else{ lll k = (-(x+y+1))/a+1; n -= k; x += a*k; } if(x+y < 0 && x+y+n*a < 0) { out(x+a*n,y); continue; } if(x+y >= 0 && x+y-n*b >= 0) { out(x,y-b*n); continue; } lll z = (x+y+a*n) % (a+b); if(z >= a) z -= a+b; if(z < -b) z += a+b; out((b*x-a*y+a*b*n+a*z)/(a+b),(a*y-b*x-a*b*n+b*z)/(a+b)); } }