#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
int gcd(int a,int b){
return b==0? a:gcd(b,a%b);
}
int main (void){
int n,q;
scanf("%d%d",&n,&q);
while(q--){
int a,b;
scanf("%d%d",&a,&b);
if(gcd(a,b)==1){
printf("1\n");
}
else {
printf("2\n");
}
}
return 0;
}