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