#include <bits/stdc++.h>
using namespace std;
bool isPrime(long x) {
  if (x % 2 == 0) return false;
  for (int i = 3; i * i <= x; i++)
    if (x % i == 0) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  ;
  long t, n, k;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    if (n < k)
      cout << 1 << "\n";
    else if (n % k == 0) {
      cout << (n / k) << "\n";
    } else if (isPrime(n)) {
      cout << n << "\n";
    } else {
      int end = ceil(sqrt(n));
      int ans = INT_MAX, i;
      if (k < end) end = k;
      for (i = 1; i <= end; i++) {
        if (n % i == 0) {
          if (n / i <= k) {
            cout << i << "\n";
            break;
          }
          if (n / i < ans) ans = n / i;
        }
      }
      if (i == end + 1) cout << ans << "\n";
    }
  }
  return 0;
}
