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