#include <bits/stdc++.h>
using namespace std;
int t;
long long n, k, ai;
void solve() {
  cin >> n >> k;
  if (n <= k)
    cout << 1;
  else {
    ai = n;
    for (long long i = 2; i * i <= n; i++) {
      if (n % i == 0) {
        if (i <= k) ai = min(ai, (n / i));
        if ((n / i) <= k) ai = min(ai, i);
      }
    }
    cout << ai;
  }
  cout << endl;
}
int main() {
  cin >> t;
  while (t--) solve();
  return 0;
}
