#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cctype>
using namespace std;

int conv(int ch, int a, int b) {
  if ( !isalpha(ch) ) return ch;
  int n = ch - 'a';
  return (char)('a' + (a * n + b) % 26);
}

int check(string line, int a, int b) {
  for(int i = 0; i < (int)line.size(); i++)
    line[i] = conv(line[i], a, b);

  return line.find("that") != string::npos ||
    line.find("this") != string::npos;
}

int main() {
  int T; cin >> T >> ws;
  while(T--) {
    string line;
    getline(cin, line);

    for(int a = 0; a < 26; a++)
      for(int b = 0; b < 26; b++)
        if( __gcd(a, b) == 1 ) {
          int res = check(line, a, b);
          if ( res ) {
            for(int i = 0; i < (int)line.size(); i++)
              cout << (char)conv(line[i], a, b);
            cout << endl;
          }
        }
  }
  return 0;
}