import sys from collections import deque, Counter input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 maxi = 10 ** 7 prime = [True] * (maxi) prime[0] = prime[1] = False for i in range(2, maxi): if prime[i]: for j in range(2 * i, maxi, i): prime[j] = False for _ in range(ii()): a, p = mi() if prime[p]: print(1) else: print(-1)