#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, k;
  scanf("%lld %lld", &n, &k);
  long long rs = n;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      {
        int d = i;
        if (d <= k) {
          rs = min(rs, n / d);
        }
      }
      {
        int d = n / i;
        if (d <= k) {
          rs = min(rs, n / d);
        }
      }
    }
  }
  printf("%lld\n", rs);
}
int main() {
  int tc;
  scanf("%d", &tc);
  while (tc--) solve();
}
