#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    unsigned long long n, k, ans = 0;
    cin >> n >> k;
    if (n <= k) {
      cout << "1" << endl;
    } else {
      for (unsigned long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
          if (i <= k) {
            ans = max(ans, i);
          }
          if (n / i <= k) {
            ans = max(ans, n / i);
          }
        }
      }
      cout << (n / ans) << endl;
    }
  }
  return 0;
}
