#include using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while(t--) { ll n, k; cin >> n >> k; if(n == k) { cout << "-1\n"; continue; } ll cur = n; while(true) { if(cur <= k) { cout << "-1\n"; break; } bool bad = false; for(ll i = 2; i * i <= cur; i++) { if(cur % i == 0) { bad = true; break; } } if(!bad || (cur > 1 && cur > k)) { cout << cur << "\n"; break; } cur--; } } }