#include <stdio.h>
#include <string.h>

void cipher(char *out, char *in, int a, int b)
{
	int i;
	
	i = 0;
	while (in[i] != '\0'){
		out[i] = ((a * (in[i] - 'a') + b) % 26) + 'a';
		i++;
	}
	out[i] = '\0';
}
	
void search_key(char *str, int *key_a, int *key_b)
{
	int a, b;
	char key_word[5];
	
	for (a = 1; a < 100; a += 2){
		for (b = 0; b < 100;  b++){
			cipher(key_word, "this", a, b);
			if (strstr(str, key_word) != NULL){
				*key_a = a;
				*key_b = b;

// printf("<%s, %d, %d>", key_word, a,  b);

				return;
			}
			cipher(key_word, "that", a, b);
			if (strstr(str, key_word) != NULL){
				*key_a = a;
				*key_b = b;
// printf("[%s, %d, %d]", key_word, a,  b);
				return;
			}
		}
	}
}

void make_decode_table(char *table, int a, int b)
{
	int c;
	
	for (c = 0; c < 26; c++){
		table[(a * c + b) % 26] = c + 'a';
	}
	table[26] = '\0';
}

void decode(char *in, char *table)
{
	int i;
	
	i = 0;
	while (in[i] != '\n'){
		if (in[i] == ' '){
			printf(" ");
		}
		else {
			printf("%c", table[in[i] - 'a']);
		}
		i++;
	}
	printf("\n");
}
	
int main(void)
{
	int n;
	int a, b;
	char str[300];
	char decode_table[27];
	int i;
	
	scanf("%d", &n);
	fgets(str, 90, stdin);
	for (i = 0; i < n; i++){
		fgets(str, 300, stdin);
		search_key(str, &a, &b);
		make_decode_table(decode_table, a, b);

//		printf("<%s>", decode_table);

		decode(str, decode_table);
	}
	
	return (0);
}


/*#include <stdio.h>
#include <string.h>

char alfa[26];
char str2[256];
char str3[256];
int keya,keyb;

void alfasort(void);
void change(char str[]);
void keyserch(char str[]);


int main(void)
{
    char str[256];
    int n;
    int i,j;
    int len;
    alfasort();

    scanf("%d", &n);
    fgets(str, 90, stdin);
    for (i = 0; i < n; i++){
        fgets(str,257,stdin);
        len = strlen(str);
        keyserch(str);
        change(str);
        printf("%s\n", str3);      
    }

    return (0);
}
void alfasort(void)
{
    int i;

    for (i = 0; i < 26; i++){
        alfa[i] = 'a' + i;
    }
    //printf("%s", alfa);
}
void keyserch(char str[])
{
    int a, b;
    char this[5] = {"this"};
    char that[5] = {"that"};
    
    int i;
    int sum;
    i = 0;
    sum = 0;
    for (a = 1; a < 100; a += 2){
        for (b = 0; b < 100; b++){
            while (this[i] != '\0')
            {
                str[i] = ((a * (this[i] - 'a') + b) % 26) + 'a';
                i++;
                printf("<%c %d>", str[i], i);
            }
            //printf("[%s]\n", str2);
            if(strstr(str, "this") != NULL){
                keya = a;
                keyb = b;
                printf("<%d %d>\n", keya,keyb);
                return;
            }
            while (that[i] != '\0')
            {
                str[i] = ((a * (that[i] - 'a') + b) % 26) + 'a';
                i++;
                printf("<%c %d>", str[i], i);
            }
            //printf("[%s]\n", str2);
            if(strstr(str, "that") != NULL){
                keya = a;
                keyb = b;
                printf("<%d %d>\n", keya,keyb);
                return;
            }

        }
    }

}
void change(char str[])
{
    int i,j;
    
    for (i = 0; i < strlen(str); i++){
        for (j = 0; j < 26; j++){
            if ((keya * j + keyb) % 26 == str[i] - 'a'){
                str3[i] = alfa[j];
                printf("%c", str3[i]);
            }else if (str[i] == ' ' || str[i] == '\n'){
                str3[i] = str[i];
            }
        }
    }
}
*/


Measured memory_bytes: 2032