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