#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) { return (y == 0) ? x : gcd(y, x % y); }
unsigned long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
int dy8[] = {0, 0, 1, -1, 1, -1, -1, 1};
int dx8[] = {1, -1, 0, 0, 1, -1, 1, -1};
int id8[] = {0, 1, 2, 3, 4, 5, 6, 7};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    if (b >= a) {
      cout << 1 << '\n';
      continue;
    }
    if (b == 1) {
      cout << a << '\n';
      continue;
    }
    long long ans = 9223372036854775807LL;
    bool ok = true;
    for (long long i = 2; i * i <= a && i <= b; i++) {
      if (a % i == 0) {
        if ((a / i) <= b) {
          ans = min(ans, i);
        } else {
          ans = min(ans, (a / i));
        }
        ok = false;
      }
    }
    if (ok)
      cout << a << '\n';
    else
      cout << ans << '\n';
  }
}
