#include <iostream>
#include <string>
using namespace std;

int isSo(int a, int b) {
  int temp;
  if(a > b) temp = b;
  else temp  = a;
  for(int i = 2; i <= temp; i++) {
    if(a % i == 0 && b % i == 0) return 0;
  }
  return 1;
}
int mod26(int x) {
  return x % 26;
}

int main(void) {
  string str, out;
  int n;
  int flag;
  cin >> n;
  getchar();
  for(int i = 0; i < n; i++) {
    getline(cin, str);
    out = str;
    flag = 0;
    for(int a = 1; a <= 26; a++) {
      if(!isSo(a, 26)) continue;
      for(int b = 1; b <= 26; b++) {
	for(int j = 0; j < (int)str.length(); j++) {
	  if(str[j] == ' ') out[j] = str[j];
	  else out[j] = (char)(mod26(a*((int)str[j]-(int)'a')+b)+(int)'a');
	}
	for(int j = 0; j < out.length()-3; j++) {
	  string temp;
	  temp = out.substr(j,4);
	  if(temp == "that" || temp == "this") {
	    flag = 1;
	    break;
	  }
	}
	if(flag) break;
      }
      if(flag) break;
    }
    cout << out << endl;
  }
  return 0;
}