#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e9;
void solve() {
  int t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    if (k >= n) {
      cout << 1 << endl;
      continue;
    }
    long long res = n;
    for (long long i = 2; i <= k && i * i <= n; ++i) {
      if (n % i == 0 && n / i <= k) {
        res = i;
        break;
      }
      if (n % i == 0) {
        res = n / i;
      }
    }
    cout << res << endl;
  }
}
int main() { solve(); }
