#include int main () { int t = 0; int res = 0; int np[300001] = {}; int nf[300001] = {}; int pcnt[300001] = {}; long long fr[300000][2] = {}; np[1] = 1; nf[1] = 1; for (int i = 2; i <= 300000; i++) { if (np[i] <= 0) { pcnt[i] = 1; for (int p = 2; i*p <= 300000; p++) { np[i*p] = 1; pcnt[i*p]++; if (p%i == 0) { nf[i*p] = 1; } } } } res = scanf("%d", &t); while (t > 0) { long long n = 0LL; long long k = 0LL; long long rcnt = 1LL; res = scanf("%lld", &n); res = scanf("%lld", &k); rcnt = n*n; for (long long i = 1LL; i <= n; i += 1LL) { if (nf[(int)i] <= 0) { long long tmp = n/i; if (pcnt[(int)i]%2 == 0) { rcnt += tmp*tmp; } else { rcnt -= tmp*tmp; } } } if (rcnt < k) { printf("-1\n"); } else { long long ans = 0LL; long long l = 0LL; long long r = (1LL<<19LL); long long div = 1LL; long long lcnt = 0LL; int frcnt = 0; while (div <= n) { long long nxt = l+r; long long cnt = 0LL; if (nxt%2LL == 1LL) { div *= 2LL; l *= 2LL; r *= 2LL; } else { nxt /= 2LL; } for (long long i = 1LL; i <= n; i += 1LL) { long long d = (nxt*i)/div; if (d > n) { d = n; } cnt += d; if (nf[(int)i] <= 0) { long long tmp = 0LL; for (long long j = 1LL; i*j <= n; j += 1LL) { long long d = (nxt*i*j)/div; if (d > n) { d = n; } tmp += d/i; } if (pcnt[(int)i]%2 == 0) { cnt += tmp; } else { cnt -= tmp; } } } if (cnt < k) { l = nxt; lcnt = cnt; } else { r = nxt; rcnt = cnt; } } printf("%lld\n", ans); } t--; } return 0; }