rt,code:
#include <iostream>
#include <map>
int main(){
std::ios::sync_with_stdio(0);
std::cin.tie(0),std::cout.tie(0);
int T,p,x,y,rounds;
std::cin >> T >> p;
while (T--){
std::map <std::pair<int,int>,bool> vis;
rounds = 0;
std::cin >> x >> y;
while (x && y){
rounds++;
if (rounds % 2 == 1) x = (x + y) % p;
else y = (x + y) % p;
if (vis[{x,y}]){
std::cout << "error\n";
break;
}
vis[{x,y}] = true;
}
if (x == 0) std::cout << "1\n";
else if (y == 0) std::cout << "2\n";
}
return 0;
}