#include using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; redo: if (n == k) { cout << "-1\n"; continue; } // This is the CORRECT lower bound: (n-1)/k + 1 // Any number with all factors <= k must have a divisor in this range for (int i = (n - 1) / k + 1; i * i <= n; i++) { if (n % i == 0) { n--; goto redo; } } cout << n << "\n"; } return 0; }