#include using namespace std; typedef long long ll; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b #define vl vector #define vii vector> #define vll vector> #define vvi vector> #define vvl vector> #define vvii vector>> #define vvll vector>> #define vst vector #define pii pair #define pll pair #define pb push_back #define all(x) (x).begin(),(x).end() #define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end()) #define fi first #define se second #define mp make_pair #define si(x) int(x.size()) const int mod=998244353,MAX=300005,INF=15<<26; pll F(ll N,ll X,ll Y,ll A,ll B){ if(N==0) return mp(X,Y); if(X+Y<0){ if(A<=0) return mp(X+A*N,Y); if(X+Y+A<0){ ll can=min(N,(-(X+Y)-1)/A); return F(N-can,X+A*can,Y,A,B); } if(B<=0){ return F(N-1,X+A,Y,A,B); } }else{ if(B<=0) return mp(X,Y-B*N); if(X+Y-B>=0){ ll can=min(N,(X+Y)/B); return F(N-can,X,Y-B*can,A,B); } if(A<=0){ return F(N-1,X,Y-B,A,B); } } ll syuu=A+B; ll sum=X+Y+A*N; sum%=(A+B); if(sum>=A) sum-=(A+B); ll y=(X+Y+A*N-sum)/(A+B); ll x=N-y; return mp(X+A*x,Y-B*y); } int main(){ std::ifstream in("text.txt"); std::cin.rdbuf(in.rdbuf()); cin.tie(0); ios::sync_with_stdio(false); int Q;cin>>Q; while(Q--){ ll N,X,Y,A,B;cin>>N>>X>>Y>>A>>B; auto res=F(N,X,Y,A,B); cout<