#include <bits/stdc++.h>
const long long INF = 1e18;
void swap(long long &a, long long &b) {
  long long temp;
  temp = a;
  a = b;
  b = temp;
}
using namespace std;
void solve() {
  long long n, k, ans;
  cin >> n >> k;
  ans = n;
  for (long long i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i <= k) ans = min(ans, i);
      if (i <= k) ans = min(ans, n / i);
    }
  }
  cout << ans;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
