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