#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, k;
  cin >> n >> k;
  long long int ans = INT_MAX;
  for (long long int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      long long int a = n / i;
      if (i <= k) ans = min(ans, a);
      if (a <= k) ans = min(ans, i);
    }
  }
  cout << ans << endl;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
