#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const long long int MOD = 1000000007;
int main() {
  int t, a, b;
  scanf("%lld", &t);
  while (t--) {
    scanf("%d %d", &a, &b);
    if (b >= a)
      printf("1");
    else {
      vector<int> v;
      bool k = false;
      int c;
      for (int i = 1; i * i <= a; i++) {
        if (a % i == 0) {
          v.push_back(i);
          v.push_back(a / i);
          k = true;
        }
      }
      if (!k)
        printf("%d", a);
      else {
        sort(v.begin(), v.end(), greater<int>());
        for (int i = 0; i < (int)v.size(); i++) {
          if (v[i] <= b) {
            printf("%d", a / v[i]);
            break;
          }
        }
      }
    }
    printf("\n");
  }
  return 0;
}
