#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const double eps = 1e-9;
vector<long long> prnum;
void sieve() {
  bool prime[1000001];
  memset(prime, true, sizeof(prime));
  for (int i = 2; i * i <= 1000000; i++) {
    if (prime[i] == true) {
      for (int j = 2 * i; j <= 1000000; j += i) {
        prime[j] = false;
      }
    }
  }
  for (int i = 2; i <= 1000000; i++) {
    if (prime[i]) prnum.push_back(i);
  }
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    if (k >= n) {
      cout << 1 << "\n";
    } else {
      long long ans = 1000000000;
      for (long long i = 1; i * i <= n; i++) {
        if (i > k) break;
        if (n % i == 0) {
          if ((n / i) <= k) {
            ans = min(ans, i);
          } else {
            ans = min(ans, n / i);
          }
        }
      }
      cout << ans << "\n";
    }
  }
  return 0;
}
