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