#include <bits/stdc++.h>
using namespace std;
bool ssyz(int n) {
  if (n == 1) return false;
  if (n == 2 || n == 3) return true;
  if (n % 6 != 5 && n % 6 != 1) return false;
  for (int i = 5; i <= sqrt(n); i += 6) {
    if (n % i == 0 || n % (i + 2) == 0) return false;
  }
  return true;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int min = n;
    if (k >= n)
      cout << 1 << endl;
    else {
      long long int min = n;
      for (long long int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0) {
          if (i < min && (n / i) <= k) min = i;
          if ((n / i) < min && n / (n / i) <= k) min = n / i;
        }
      }
      cout << min << endl;
    }
  }
  return 0;
}
