#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k;
  cin >> n >> k;
  int y = sqrt(n) + 1;
  int maxi = 0;
  int x = min(y, k);
  for (int i = 1; i <= x; ++i) {
    if (n % i) continue;
    maxi = max(maxi, i);
    if (n / i <= k) maxi = max(maxi, n / i);
    if (n % (x / i) == 0 && (x / i) <= k) maxi = max(maxi, x / i);
  }
  cout << (n / maxi) << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
