#include <stdio.h>
#include <stack>

using namespace std;


//??¨??¬??????a,b????????????????????????????????¢??°
bool judge(int a, int b){
	int checkTable[26];
	for(int i=0;i<26;i++)checkTable[i] = 0;
	for(int i=0;i < 26;i++){
		if(checkTable[(a*i+b)%26] == 0){
			checkTable[(a*i+b)%26] = 1;
		}else{
			return false;
		}
	}
	return true;
}


int main(){
	int n,length,a,b;
	char buf[300],convert[26],s1,s2,s3,s4;
	bool FLG;

	scanf("%d",&n);
	getchar();
	for(int i=0;i<n;i++){
		fgets(buf,300,stdin);
		length = 0;
		FLG = false;
		//??????4?????????????????¢??????a,b?????????????????????
		for(int k=0;buf[k] != '\0';k++){
			if(buf[k] == ' '){
				if(length == 4){

					s1 = buf[k-4] - 97;
					s2 = buf[k-3] - 97;
					s3 = buf[k-2] - 97;
					s4 = buf[k-1] - 97;

					//this??§??¨??¬
					if(s1 > s4){
						a = s1 - s4;
					}else{
						a = (s1 + 26) -s4;
					}
					b = -1;
					for(int p=0;p<26;p++){
						if((19*a+p)%26==s1){
							b = p;
							if(judge(a,b) && (19*a+b)%26 == s1 && (7*a+b)%26 == s2 && (8*a+b)%26 == s3 && (18*a+b)%26 == s4){
								FLG = true;
								break;
							}
						}
					}
					if(FLG){
						break;
					}

					if(s1 == s4){
						//that??§??¨??¬
						a = -1;
						b = s3;
						for(int p=0;p<26;p++){
							if((19*p+b)%26==s1){
								a = p;
								if(judge(a,b) && (19*a+b)%26 == s1 && (7*a+b)%26==s2){
									FLG = true;
									break;
								}
							}
						}
						if(FLG){
							break;
						}
					}
				}
				length = 0;
			}else if(buf[k+1] == '\0'){
				length++;
				if(length == 4){

					s1 = buf[k-3] - 97;
					s2 = buf[k-2] - 97;
					s3 = buf[k-1] - 97;
					s4 = buf[k] - 97;

					//this??§??¨??¬
					if(s1 > s4){
						a = s1 - s4;
					}else{
						a = (s1 + 26) -s4;
					}
					b = -1;
					for(int p=0;p<26;p++){
						if((19*a+p)%26==s1){
							b = p;
							if(judge(a,b) && (19*a+b)%26 == s1 && (7*a+b)%26 == s2 && (8*a+b)%26 == s3 && (18*a+b)%26 == s4){
								FLG = true;
								break;
							}
						}
					}
					if(FLG){
						break;
					}


					//that??§??¨??¬
					if(s1 == s4){
						a = -1;
						b = s3;
						for(int p=0;p<26;p++){
							if((19*p+b)%26==s1){
								a = p;
								if(judge(a,b) && (19*a+b)%26 == s1 && (7*a+b)%26==s2){
									FLG = true;
									break;
								}
							}
						}
						if(FLG){
							break;
						}
					}
				}
				length = 0;
			}else{
				length++;
			}
		}

		//????????¨?????????
		for(int k = 0; k < 26;k++)convert[(a*k+b)%26] = k;

		for(int k=0;buf[k] != '\0';k++){
			if(buf[k]>=97 && buf[k] <= 122){
				buf[k] = convert[buf[k]-97]+97;
			}
		}
		printf("%s\n",buf);
	}

    return 0;
}