#include <bits/stdc++.h>
using namespace std;
int n, k, fact;
void isprime() {
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (i <= k) fact = max(fact, i);
      if ((n / i) <= k) fact = max(fact, (n / i));
    }
  }
}
int package() {
  isprime();
  return n / fact;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    fact = 0;
    cout << package() << "\n";
  }
  return 0;
}
