#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int gcd(int x,int y)
{
int c=x%y;
while(c)
{
x=y;
y=c;
c=x%y;
}
return y;
}
int main()
{
int n,q;
cin>>n>>q;
for(int i=1;i<=q;i++)
{
int a,b;
scanf("%d%d",&a,&b);
int min=gcd(a,b);
if(min!=1)
printf("2\n");
else printf("%d\n",min);
}
return 0;
}