#include <bits/stdc++.h>
using namespace std;
vector<long long> Divisors(long long n) {
  vector<long long> d;
  for (long long i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        d.push_back(i);
      else {
        d.push_back(i);
        d.push_back(n / i);
      }
    }
  }
  return d;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    if (n <= k) {
      cout << 1 << "\n";
      continue;
    }
    vector<long long> d = Divisors(n);
    sort(d.rbegin(), d.rend());
    for (auto i : d) {
      if (i <= k) {
        cout << n / i << "\n";
        break;
      }
    }
  }
}
