#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
inline long long max3(long long a, long long b, long long c) {
  return (a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c));
}
inline long long min3(long long a, long long b, long long c) {
  return (a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c));
}
bool isPrime(int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
void solve() {
  long long int n, m, t = 0, k = 0, x = 0, y = 0, z = 0, ex, che, var, yd,
                      f = 9223372036854775807;
  cin >> n >> k;
  if (k >= n) {
    cout << "1\n";
    return;
  }
  if (n % 2 == 0 && k >= n / 2) {
    cout << 2 << "\n";
    return;
  }
  if (isPrime(n)) {
    cout << n << "\n";
    return;
  }
  if (k == 1) {
    cout << n << "\n";
    return;
  }
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if ((n / i) <= k) {
        x = n / i;
        break;
      }
      if (i <= k) x = i;
    }
  }
  cout << n / x << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int T = 1, t = 0;
  cin >> T;
  while (t++ < T) {
    solve();
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
}
