#include <iostream>
#include <cstring>
using namespace std;

int main(){
	int n;
	string str;
	bool output;
	int code;
	int str1[4] = {19, 7, 8, 18};
	int str2[4] = {19, 7, 0, 19};
	
	cin >> n;
	
	getline(cin, str);
	for(int i = 0; i < n; i++){
		getline(cin, str);
		
		output = false;
		
		for(int a = 0; !output && a < 26; a++){
			for(int b = 0; !output && b < 26; b++){
				for(int p = 0; !output && p < str.size() - 4; p++){
					for(int c = 0; !output && c < 4; c++){
						code = (a * (str[p + c]-97) + b) % 26;
						if(code != str1[c]) break;
						else if(c + 1 == 4){
							output = true;
							for(int P = 0; P < str.size(); P++){
								if(str[P] != ' ') cout << (char)((a * (str[P]-97) + b) % 26 + 97);
								else cout << " ";
							}
							cout << endl;
						}
					}
					for(int c = 0; !output && c < 4; c++){
						code = (a * (str[p + c]-97) + b) % 26;
						if(code != str2[c]) break;
						else if(c + 1 == 4){
							output = true;
							for(int P = 0; P < str.size(); P++){
								if(str[P] != ' ') cout << (char)((a * (str[P]-97) + b) % 26 + 97);
								else cout << " ";
							}
							cout << endl;
						}
					}
				}
			}
		}
	}
	
	return 0;
}