#include <bits/stdc++.h>
using namespace std;
int a[100050];
int n, t, k;
int x, y;
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> k;
    int p;
    int d = 0;
    if (n <= k) {
      cout << "1" << endl;
      continue;
    }
    int s = sqrt(n);
    s = min(s, k);
    for (int i = s; i >= 1; i--) {
      if (n % i == 0) {
        if (n / i > i && n / i <= k)
          p = n / i;
        else
          p = i;
        d = max(p, d);
      }
    }
    cout << n / d << endl;
  }
  return 0;
}
