#include

using namespace std;

int main() {

int t;

long long int n,m;

cin>>t;

while(t–)

{ int sum=0;

long long int num=0,rem;

cin>>n>>m;

num=n*m;

while(num>0)

{ rem=num%10;

sum+=rem;

num=num/10;

```
}
int temp;
temp=sum%3;
cout<<temp<<endl;
```

}

return 0;

}