#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int maxDiv = 0;
    int ans = -1;
    for (int i = 1; i * i <= n; i++) {
      if (n % i == 0) {
        if (n / i <= k) {
          ans = i;
          break;
        }
        if (i <= k) maxDiv = i;
      }
    }
    if (ans == -1) {
      ans = n / maxDiv;
    }
    cout << ans << endl;
  }
}
