Go: package main

import (
	"bufio"
	"os"
	"fmt"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		s := scanner.Text()
		rs := []rune(s)
		flag := false
		for b := 0; b <= 26; b++ {
			for a := 0; a <= 26; a++ {
				ans := rs
				if a%2 != 0 && a%13 != 0 {
					for j := 0; j < len(ans); j++ {
						if ans[j] > 'a' && ans[j] <= 'z' {
							ans[j] = 'a' + ('a'*(ans[j]-'a')+'b')%26
						}
					}
					sans := runeSlice2String(ans)
					if strings.Contains(sans, "that") || strings.Contains(sans, "this") {
						fmt.Println(sans)
						flag = true
						break
					}
				}
			}
			if flag {
				break
			}
		}
	}
}

func runeSlice2String(input []rune) string {
	tmp := make([]string, len(input))
	for i := 0; i < len(input); i++ {
		tmp[i] = string(input[i])
	}
	return strings.Join(tmp, "")
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
	
int F(int alpha,int beta,int ch){
	return (alpha*ch+beta)%26;
}
int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}
int main(){
	int n;
	string in,s,ans;
	cin>>n;
	getline(cin,in);
	while(n--){
		getline(cin,in);
		for(int i=1;i<26;i++){
			if(gcd(26,i)!=1)continue;
			for(int j=0;j<26;j++){
				int table[26];
				for(int k=0;k<26;k++){
					table[F(i,j,k)] = k;
				}
				s.resize(in.size());
				for(int k=0;k<in.size();k++){
					if(in[k]==' ')s[k]=' ';
					else s[k] = table[in[k]-'a']+'a';
				}
				if(s.find("that",0)!=string::npos
					|| s.find("this",0)!=string::npos){
					cout<<s<<endl;
					goto BREAK;
				}
			}
		}
		BREAK:;
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    map<char, int> t;
    string s, s_trans;
    int n;
    char m[26];
    string suuti;
    cin >> n;
    getline(cin, s);
    rep(i, 26)
    {
        m[i] = char('a' + i);
        t[m[i]] = i;
    }

    rep(i, n)
    {
        bool flag = 0;
        getline(cin, s);
        s_trans = s;
        rep(a, 26)
        {
            rep(b, 26)
            {
                rep(k, s.size())
                {
                    if (s[k] == ' ')
                        s_trans[k] = ' ';
                    else
                        s_trans[k] = m[a * (t[s[k]] - b + 26) % 26];
                }
                if (s_trans.find("this") != string::npos || s_trans.find("that") != string::npos)
                {
                    flag = 1;
                    break;
                }
            }
            if (flag == 1)
                break;
        }
        OP(s_trans)
    }

    return 0;
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <map>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;

int main()
{
	int n;
	scanf("%d%*c", &n);
	rep(i, n){
		char str[258];
		fgets(str, 258, stdin);

		set<string> words;
		stringstream stin(str);
		string tmp;
		while(stin >> tmp){
			if(tmp.size() == 4)
				words.insert(tmp);
		}

		int alpha=0, beta=0;
		bool keep = true;
		for(int i=1; keep; ++i){
			if(i%2==0 || i%13==0)
				continue;
			rep(j, 26){
				char samples[][5] = {"that", "this"};
				rep(k, 2){
					rep(l, 4) samples[k][l] = ((samples[k][l]-'a')*i+j)%26+'a';
					if(words.count(string(samples[k]))){
						alpha = i;
						beta = j;
						j=100;
						keep = false;
					}
				}
			}
		}

		map<char, char> conv;
		rep(i, 26)
			conv.insert(make_pair((i*alpha+beta)%26+'a', i+'a'));
		rep(i, strlen(str))
			putchar(isalpha(str[i]) ? conv[str[i]] : str[i]);
	}

	return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;

int code[26];

int gcd(int x, int y){
  if(y == 0) return x;
  return gcd(y, x % y);
}

int affine(int m, int a, int b){
  return (m * a + b) % 26;
}

int main(void){
  int n;
  string p;
  cin >> n; cin.ignore();
  while(n--){
    getline(cin, p);
    bool finded = false;
    for(int a = 1; a < 26; a++){
      if(finded) break;
      if(gcd(a, 26) != 1) continue;

      for(int b = 1; b < 26; b++){
        for(int i = 0; i < 26; i++){
          code[affine(i, a, b)] = i;
        }

        string c = "";
        for(int i = 0; i < p.size(); i++){
          if(p[i] == ' ') c += " ";
          else c += (char)(code[p[i] - 'a'] + 'a');
        }

        bool tis = c.find("this", 0) != string::npos;
        bool tht = c.find("that", 0) != string::npos;
        if(tis || tht){
          cout << c << endl;
        }
      }
    }
  }
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;

int main() {
	string sa;
	string th,ta;
	int i=0, j=0;
	int n;
	size_t ind;
	size_t in;
	cin >> n;
	for (int ia = 0; ia < n; ia++) {
		getline(cin,sa);
		for (i = 0; i < 26; i++) {
			for (j = 0; j < 26; j++) {
				th[0] = (i*('t' - 97) + j) % 26 + 'a';
				th[1] = (i*('h' - 97) + j) % 26 + 'a';
				th[2] = (i*('a' - 97) + j) % 26 + 'a';
				th[3] = th[0];
				ind = sa.find(th);
				if (ind != string::npos) { goto FINLOOP; }
				ta[0] = (i*('t' - 97) + j) % 26 + 'a';
				ta[1] = (i*('h' - 97) + j) % 26 + 'a';
				ta[2] = (i*('i' - 97) + j) % 26 + 'a';
				ta[3] = (i*('s' - 97) + j) % 26 + 'a';
				in = sa.find(ta);
				if (ind != string::npos) { goto FINLOOP; }
			}
		}
		FINLOOP:
		int a = sa.size();
		for (int ia = 0; ia < a; ia++) {
			if (sa[i] >= 'a'&&sa[i] <= 'z') {
				sa[i] = (i*(sa[i] - 97) + j) % 26 + 'a';
			}
		}
		cout << sa << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>

int main(){
	int n;
	std::cin >> n;
	std::cin.ignore();
	
	for(int i = 0; i < n; i++){
		std::string str;
		std::getline(std::cin, str);

		for(int a = 1; a < 26; a++){
			for(int b = 1; b < 26; b++){
				std::string str2 = str;
				for(int j = 0; j < str2.size(); j++){
					if(str2[j] != ' ')str2[j] = ((a * (str2[j] - 'a') + b) % 26) + 'a';
				}
				if(str2.find("that") != -1 || str2.find("this") != -1){
					std::cout << str2 << std::endl;
					goto end;
				}
			}
		}
		end:;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<sstream>
int calc_alpha(const std::string&w, const char*str)
{
	auto distance = [](char from, char to)
	{
		int result = static_cast<int>(to - from);
		return result + (result < 0 ? 26 : 0);
	};
	int dis1[3], ratio[3];
	for (int j = 0; j < 3; j++)
	{
		dis1[j] = distance(w[j], w[j + 1]);
		int dis2 = distance(str[j], str[j + 1]);
		while (true)
		{
			if (dis1[j] % dis2 == 0)
			{
				ratio[j] = dis1[j] / dis2;
				break;
			}
			dis1[j] += 26;
		}
	}
	return ratio[0] == ratio[1] && ratio[1] == ratio[2] ? ratio[0] : -1;
}
int main()
{
	int n;
	std::cin >> n;
	std::cin.ignore();
	for (int i = 0; i < n; i++)
	{
		std::string str;
		std::getline(std::cin, str);
		std::stringstream ss(str);
		int alpha, beta;
		for (std::string w; ss >> w;)
		{
			if (w.length() == 4)
			{
				alpha = w[0] == w[3] ? calc_alpha(w, "that") : calc_alpha(w, "this");
				if (alpha != -1)
				{
					beta = static_cast<int>(w[0] - 'a' - ('t' - 'a') * alpha % 26);
					break;
				}
			}
		}
		char deciphered[26];
		for (char j = 'a'; j <= 'z'; j++)
		{
			char ciphered = ((j - 'a') * alpha + beta) % 26 + 'a';
			deciphered[ciphered - 'a'] = j;
		}
		for (auto j : str)
		{
			if (j == ' ')
			{
				std::cout << ' ';
			}
			else
			{
				std::cout << deciphered[j - 'a'];
			}
		}
		std::cout << std::endl;
	}
	return 0;
}