def is_prime(n): if n==1:return False for i in range(2,int(n**0.5)+1): if n%i==0:return False return True for _ in range(int(input())): a,p=map(int,input().split()) if is_prime(p):print(1) else:print(-1)