#include <bits/stdc++.h>
using namespace std;
const long long Max = 5005;
int main() {
  std::ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    if (n <= k) {
      cout << 1 << '\n';
      continue;
    }
    long long ans = n;
    for (long long i = 2; i * i <= n; i++) {
      if (n % i) continue;
      if (i <= k) ans = min(ans, n / i);
      long long temp = n / i;
      if (temp <= k) ans = min(ans, n / temp);
    }
    cout << ans << '\n';
  }
}
