#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, t, k;
  vector<int> div;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    for (int i = 1; i <= sqrt(n); i++) {
      if (n % i == 0) {
        int j = n / i;
        if (j != i) {
          div.push_back(i);
          div.push_back(j);
        } else
          div.push_back(i);
      }
    }
    int ans;
    sort(div.begin(), div.end());
    for (int i = div.size() - 1; i >= 0; i--) {
      if (div[i] <= k) {
        ans = n / div[i];
        break;
      }
    }
    cout << ans << endl;
    div.clear();
  }
}
