#!/bin/python3 import sys q = int(input().strip()) for a0 in range(q): len,c = input().strip().split(' ') len,c = [int(len),int(c)] #edge case if len == 1 and c == 0: print(1) #too many comparisons: elif ((len - 1)**2 + (len - 1)) < c: print(-1) #too few comparisons elif c < (len - 1): print(-1) #get to work else: print("placeholder")