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

int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		string s;
		getline(cin,s);
		istringstream t(s);
		bool x = false;
		string u[1000];
		for(int a=0;a<26;a++){
			for(int b=0;b<=26;b++){
				int c = 0;
				while(getline(t,u[c],' ')){
					for(int j=0;j<u[c].size();j++) u[c][j] = (a*u[c][j]+b-'a')%26 + 'a';
					if(u[c]=="that" or u[c]=="this") x = true;
					c++;
					cout << u[c] << endl;
				}
				if(x){
					cout << u[0];
					for(int j=1;j<c;j++) cout << " " << u[j];
					cout << endl;
					return 0;
				}
			}
		}
	}
}