#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k;
  cin >> n >> k;
  int no = sqrt(n), result = INT_MAX;
  while (no > 0) {
    if (n % no == 0 && no <= k) {
      int no1 = n / no;
      if ((n / no) <= k)
        result = min(result, min(no1, (n / no1)));
      else
        result = min(result, no1);
    }
    no--;
  }
  cout << result << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
