#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long t;
  cin >> t;
  while (t--) {
    long long a, k;
    cin >> a >> k;
    long long ans = INT_MAX;
    for (long long i = 1; i <= min(k, (long long)sqrt(a)); i++) {
      if (a % i == 0) {
        ans = min(ans, a / i);
        if ((a / i) <= k) {
          ans = min(ans, i);
        }
      }
    }
    cout << ans << "\n";
  }
}
