#include<iostream>
#include<string>
#include<map>
using namespace std;

int main(){

	int n, cnt_alph, cnt_word, valid, b;
	string str, word[51];
	map<int, char> mp;

	for(int i=0; i<26; i++){
		mp.insert(make_pair(i, 'a'+i));
	}

	cin >> n;
	getline(cin, str);

	for(int i=0; i<n; i++){
		cnt_alph = 0;
		cnt_word = 0;
		valid = 0;
	
		getline(cin, str);

		for(int j=0; j<str.length(); j++){
			if(str[j] != ' '){
				word[cnt_word] += str[j];
				cnt_alph++;
			}
			else {
				if(cnt_alph == 4)	cnt_word++;
				else word[cnt_word] = "";
				cnt_alph = 0;
			}
			if(j == str.length() - 1){
				if(cnt_alph == 4)	cnt_word++;
			}
		}
		for(int a=0; valid == 0; a++){
				for(int j=0; j<cnt_word; j++){
					if('t'-'a' > a*(word[j][1]-'a')){
						b = 't'-'a' - a*(word[j][1]-'a');
					}
					else{
						b = a*(word[j][1]-'a') - ('t'-'a');
					}
						if(mp[(a*(word[j][1]-'a')+b)%26] == 'h'){
							if((mp[(a*(word[j][2]-'a')+b)%26] == 'a' && word[j][0] == word[j][3]) || (mp[(a*(word[j][2]-'a')+b)%26] == 'i' && mp[(a*(word[j][3]-'a')+b)%26] == 's')){
								for(int k=0; k<str.length(); k++){
									if(str[k] != ' '){
										str[k] = mp[(a*(str[k]-'a')+b)%26];
									}
									cout << str[k];
								}
								cout << endl;
								valid = 1;
							}
						}
				}
		}
	}

	return 0;

}