import sys input = sys.stdin.readline T=int(input()) for tests in range(T): N,A,W,K=map(int,input().split()) if K!=N: OK=-2 NG=1<<60 while NG-OK>1: # K-1人がOK+1点、一人がOK取れるか? mid=(OK+NG)//2 if (mid+1)*(K-1)+mid<=A: OK=mid else: NG=mid if OK>=0: print(OK) continue if W>=N-K: print(-1) continue else: print(":(") continue ANS=A//N MINUS=(W+N-1)//N ANS-=MINUS*(MINUS+1)//2 if A%N==N-1 or W%N==1: print(ANS) elif A>=N-1: print(ANS-1) elif W>=2: print(A//N-(MINUS+1)*(MINUS+2)//2) else: print(":(")