#include <iostream>
using namespace std;
int G(int x)
{
int ret = 0;
for(int i = 1; i <= x / 2; i++)
if(x % i == 0)
ret++;
return ret + 1;
}
int main()
{
int n, a, b, ret, i, g, gmax;
cin >> n;
while(n--)
{
cin >> a >> b;
ret = a;
gmax = G(a);
for(i = a + 1; i <= b; i++)
{
g = G(i);
if(g > gmax)
{
gmax = g;
ret = i;
}
}
cout << ret << endl;
}
return 0;
}