/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>
typedef long long LL;
using namespace std;
int t;
int x, y;
int f[5005];
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
for (int i = 1; i <= 5000; i++){
f[i] += 1;
for (int j = i + i; j <= 5000; j += i){
f[j] += 1;
}
}
scanf("%d", &t);
while(t--){
scanf("%d %d", &x, &y);
int maxx = 0;
int ans = x;
for (int i = x; i <= y; i++){
if(maxx < f[i]){
maxx = f[i];
ans = i;
}
}
printf("%d\n", ans);
}
return 0;
}
/**/