#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

/*
   this 19 7 8 18
   that 19 7 0 19

 */

int main(){
    char str[256][256];
    char inp[256];
    int len,n, a,b,l;
    int This[4] = {19, 7, 8, 18}, That[4] = {19, 7, 0, 19};
    while(cin >> n){
        rep(i,n){
            len = 0;
            while(cin >> inp){
                strcpy(str[len], inp);
                len++;
                if(strlen(inp) == 4){
                    bool thisc, thatc;
                    l = 0;
                    rep(j,100){
                        rep(k,100){
                            thisc = thatc = false;
                            if((j * This[l] + k) % 26 == inp[l] - 'a'){
                                for(l = 1; l < 4; l++){
                                    if((j * This[l] + k) % 26 == inp[l] - 'a'){
                                        thisc =true;
                                    }else{
                                        thisc = false;
                                        break;
                                    }
                                }
                            }
                            if(thisc){
                                a = j;
                                b = k;
                            }
                            if((j * That[l] + k) % 26 == inp[l] - 'a'){
                                for(l = 1; l < 4; l++){
                                    if((j * That[l] + k) % 26 == inp[l] - 'a'){
                                        thatc =true;
                                    }else{
                                        thatc = false;
                                        break;
                                    }
                                }
                            }
                            if(thatc){
                                a = j;
                                b = k;
                            }
                        }
                    }
                }
            }
        }
        rep(j,len){
            rep(k, strlen(str[j])){
                rep(l,26){
                    if((a * l + b) % 26 == str[j][k] - 'a'){
                        printf("%c",'a' + l);
                    }
                }
            }
            cout << ' ';
        }
        cout << endl;
    }
}