#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<iostream>
#include<set>
#include<stdlib.h>
#include<vector>
using namespace std;
const int maxn=1e5+10;
const int inf=0x3f3f3f3f;
int gcd(int a,int b){
if(a%b==0)return b;
return gcd(b,a%b);
}
int main(){
int n,q;
scanf("%d%d",&n,&q);
while(q--){
int s,t;
scanf("%d%d",&s,&t);
if(gcd(s,t)==1){
printf("1\n");
}
else{
printf("2\n");
}
}
}