#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  for (; b; a %= b, swap(a, b))
    ;
  return a;
}
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    if (n <= k)
      cout << "1"
           << "\n";
    else {
      long long div = 1;
      for (long long i = 2; i * i <= n; i++) {
        if (n % i == 0) {
          if (i <= k && div < i) div = i;
          if ((n / i) <= k && div < (n / i)) div = (n / i);
        }
      }
      cout << n / div << "\n";
    }
  }
}
