#include using namespace std; typedef long long ll; const int MAXP = 1000010; vector primes; bool is_composite[MAXP]; void sieve() { memset(is_composite, 0, sizeof(is_composite)); is_composite[0] = is_composite[1] = true; for (ll i = 2; i < MAXP; i++) { if (!is_composite[i]) { primes.push_back((int)i); for (ll j = i * i; j < MAXP; j += i) is_composite[j] = true; } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); sieve(); int T; cin >> T; while (T--) { int n, k; cin >> n >> k; if (n == k) { cout << "-1\n"; continue; } long long ans = -1; // 1. Try every prime p > k for (int p : primes) { if (p <= k) continue; if (p > n) break; ans = max(ans, (long long)(n / p) * p); } // 2. If n has a prime factor > k (could be a large prime itself) int rem = n; for (int p : primes) { if (1LL * p * p > rem) break; while (rem % p == 0) rem /= p; } if (rem > k) ans = max(ans, (long long)n); cout << ans << "\n"; } return 0; }