#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long int tc;
  cin >> tc;
  while (tc--) {
    long int n, i, j, k, temp;
    long int a, b, ans = 1000000009, q = 0;
    cin >> a >> b;
    if (a <= b)
      cout << "1" << endl;
    else {
      q = sqrt(a);
      q = min(q, b);
      for (i = 1; i <= q; ++i) {
        if (a % i == 0) {
          j = a / i;
          ans = min(ans, j);
          if (j <= b) {
            ans = min(ans, i);
          }
        }
      }
      cout << ans << endl;
    }
  }
  return 0;
}
