import math for _ in[0]*int(input()): D,A,B,K=map(int,input().split());l,h=0,A*B*K+2 if A*B%D<1 and D*K+math.gcd(D,A)>=A:D,l,h=1,-1,0 while l+1