#include #include #include #include #include #include using namespace atcoder; using namespace std; using ll = long long; using ull = unsigned long long; template using max_heap = priority_queue; template using min_heap = priority_queue, greater<>>; ll ll_min = numeric_limits::min(); ll ll_max = numeric_limits::max(); ll ALPHABET_N = 26; using mint = modint998244353; #define rep(i, n) for (ll i = (ll)0; i < (ll)n; i++) #define rep_(i, k, n) for (ll i = (ll)k; i < (ll)n; i++) #define all(a) a.begin(), a.end() int main() { ios::sync_with_stdio(false); cin.tie(0); ll t; cin >> t; rep(_, t) { ll n, k; cin >> n >> k; if (n <= k) { cout << -1 << endl; continue; } else if (k * k < n) { cout << n << endl; continue; } auto isBad = [&](ll x) -> bool { ll l = (x % k == 0 ? x / k : x / k + 1); ll root = sqrtl(x); ll cost1 = root; ll cost2 = (k >= l ? k - l + 1 : 0); if (cost1 < cost2) { for (ll t = 1; t <= root; t++) { if (x % t) continue; ll u = x / t; if (t <= k && u <= k) return true; } return false; } else { if (l > k) return false; for (ll a = l; a <= k; a++) { if (x % a == 0) return true; } return false; } }; ll ans = -1; for (ll x = n; x > k; x--) { if (!isBad(x)) { ans = x; break; } } cout << ans << endl; } return 0; }