import sys input = sys.stdin.readline T=int(input()) for tests in range(T): N,X,Y,A,B=list(map(int,input().split())) D=dict() while N>0: #print(X,Y,N) if X+Y in D: mae,maeX,maeY=D[X+Y] q=(mae)-(N) k=N//q N-=k*q X-=(maeX-X)*k Y-=(maeY-Y)*k else: D[X+Y]=(N,X,Y) if X+Y<0: if A==0: N=0 elif A>0: k=-(X+Y) kai=(k+A-1)//A MIN=min(N,kai) N-=MIN X+=MIN*A else: X+=N*A N=0 elif X+Y>=0: if B==0: N=0 elif B>0: k=(X+Y) kai=(k+B)//B MIN=min(N,kai) N-=MIN Y-=MIN*B else: Y-=N*B N=0 print(X,Y)