#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, k, maxa = 1;
    cin >> n >> k;
    long long root = sqrt(n);
    if (n % root != 0) root -= 1;
    for (long long i = 1; i <= root; i++) {
      long long div = n / i;
      if (div <= k && div * i == n)
        maxa = max(maxa, div);
      else if (i <= k && n % i == 0)
        maxa = max(maxa, i);
    }
    long long ans = n / maxa;
    cout << ans << endl;
  }
  return 0;
}
