#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    if (n <= k)
      cout << "1\n";
    else {
      long long int ans = INT_MAX;
      for (long long int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
          if (i <= k) ans = min(ans, n / i);
          if (n / i <= k) ans = min(ans, i);
        }
      }
      cout << ans << "\n";
    }
  }
  return 0;
}
