#include<iostream>
#include<string>
using namespace std;
int main(){
int n, sum, flag ;
cin >> n;
string s;
int a[17] = { 7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2 };
int num = 0;
char c[11] = { '1','0','X','9','8','7','6','5','4','3','2' };
for (int i = 0; i<n; i++){
sum = flag = 0;
cin >> s;
for (int j = 0; j<17; j++){ //需保证前17位全为数字
if (isdigit(s[j]))
sum = sum + ((int)s[j] - '0')*a[j];
else {
cout << s << endl;
flag = 1;
break;
}
}
if (!flag) {
sum %= 11;
if (s[17] != c[sum]) {
cout << s << endl;
continue;
}
num++;
}
}
if (num == n)
cout << "All passed";
return 0;
}