#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t > 0) {
    vector<long long> v;
    int n, k;
    cin >> n >> k;
    vector<long long> vec;
    int w = 1;
    while (w * w <= n) {
      if (n % w == 0) {
        vec.push_back(w);
        if (n / w != w) {
          vec.push_back(n / w);
        }
      }
      w++;
    }
    sort(vec.begin(), vec.end());
    int ans = 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10;
    if (k > n) {
      ans = 1;
    } else {
      for (int i = 0; i < vec.size(); i++) {
        if (vec[i] <= k) {
          int x = n / vec[i];
          ans = min(ans, x);
        }
      }
    }
    cout << ans;
    cout << "\n";
    t--;
  }
}
