#include <bits/stdc++.h>
using namespace std;
unsigned long long t, k, a, b;
long long num1, num2;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> num1 >> num2;
    long long z = sqrt(num1);
    long long answer = 0;
    vector<int> vec;
    for (int j = 1; j <= z; j++) {
      if (num1 % j == 0) {
        if (num1 / j <= num2) {
          answer = j;
          break;
        }
        vec.push_back(j);
      }
    }
    if (answer) {
      cout << answer << endl;
      continue;
    }
    for (int j = vec.size() - 1; j >= 0; j--) {
      if (vec[j] <= num2) {
        answer = num1 / vec[j];
        break;
      }
    }
    cout << ((answer) ? answer : num1) << endl;
  }
  return 0;
}
