#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
long long google_itr = 1;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
long long popcount(long long num) {
  num = num - ((num >> 1) & 0x55555555);
  num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
  return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
void virus() {
  long long n, k;
  cin >> n >> k;
  long long mn = LLONG_MAX;
  for (long long i = 1; i <= min(k, (long long)sqrt(n + 1)); i++) {
    if (n % i == 0) {
      mn = min(mn, (n / i));
      if ((n / i) <= k) {
        mn = min(mn, i);
      }
    }
  }
  cout << mn << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    auto start = high_resolution_clock::now();
    virus();
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<seconds>(stop - start);
  }
  return 0;
}
