#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<long long int> v;
  long long int t, n, k, i;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    for (i = 1; i * i <= n; i++) {
      if (n % i == 0) {
        v.push_back(i);
        v.push_back(n / i);
      }
    }
    sort(v.rbegin(), v.rend());
    for (i = 0; i < v.size(); i++) {
      if (v[i] <= k) {
        cout << n / v[i] << endl;
        break;
      }
    }
    v.clear();
  }
  return 0;
}
