#include<cstdio>
#include<cstring>

char affine(char c, int a, int b){
	return (a * (c - 'a') + b) % 26 + 'a';
}

int main(){
	int n;
	char t = 'a';
	char s[257];
	char that[] = "that";
	char thi[] = "this";
	char athat[5], athis[5], r[26], rt[26];
	scanf("%d\n", &n);
	for(int i = 0; i < n; i++){
		int d = 0;
		int a = 0;
		scanf("%c", &t);
		while(t - 10){
			s[d] = t;
			d++;
			scanf("%c", &t);
		}
		s[d] = 0;
		while(a + 1){
			for(int b = 0; b < 26; b++){
				for(int c = 0; c < 4; c++){
					athat[c] = affine(that[c], a, b);
					athis[c] = affine(thi[c], a, b);
				}
				athat[4] = 0;
				athis[4] = 0;
				if(strstr(s, athat) || strstr(s, athis)){
					for(int j = 0; j < 26; j++){
						rt[j] = affine(j + 'a', a, b) - 'a';
						r[rt[j]] = j;
					}
					d = 0;
					while(s[d]){
						if(s[d] != ' '){
							printf("%c", r[s[d] - 'a'] + 'a');
						}else{
							printf(" ");
						}
						d++;
					}
					printf("\n");
					a = -2;
				}
			}
			a++;
		}

	}	
}