#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, k;
  cin >> n >> k;
  vector<long long int> f;
  for (long long int i = 1; i <= sqrt(n); i++)
    if (n % i == 0) {
      if ((n / i) == i)
        f.push_back(i);
      else
        f.push_back(i), f.push_back(n / i);
    }
  sort(f.begin(), f.end());
  long long int ans = INT_MAX;
  for (long long int i = 0; i < f.size(); i++) {
    if (f[i] > k) break;
    ans = min(ans, n / f[i]);
  }
  cout << ans << "\n";
}
int main() {
  std::ios_base::sync_with_stdio(false);
  long long int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
