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 <sstream>
using namespace std;

string convert(int a, int b, string str) {
    for (int i = 0; i < (int)str.length(); ++i) {
        if (str[i] != ' ')
            str[i] = char((a * (str[i] - 'a') + b) % 26 + 'a');
    }
    return str;
}


int main(void) {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        bool flag = false;
        string str;
        getline(cin, str);
        getline(cin, str);
        for (int a = 0; a < 26; ++a) {
            for(int b = 0; b < 26; ++b) {
                string str2;
                stringstream ss;
                ss << convert(a, b, str);
                while (!ss.eof()) {
                    ss >> str2;
                    if (str2 == "this" || str2 == "that") {
                        cout << convert(a, b, str) << endl;
                        flag = true;
                        break;
                    }
                }
                if (flag)
                    break;
            }
            if (flag)
                break;
        }
    }
    return 0;
}

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

using namespace std;

int gcd(int a,int b){
  return (b==0)?a:gcd(b,a%b);
}

int main(){
  int n;
  cin>>n;
  cin.ignore();
  while(n--){
    string s;
    getline(cin,s);
    for(int a=1;;a++){
      if(gcd(26,a)!=1)continue;
      for(int b=0;b<26;b++){
	char dt[128];
	dt[' ']=' ';
	for(int c='a';c<='z';c++){
	  dt[(a*(c-'a')+b)%26+'a']=c;
	}
	string t(s);
	for(int i=0;i<t.size();i++){
	  t[i]=dt[t[i]];
	}
	if(t.find("that")!=t.find("this")){
	  cout<<t<<endl;
	  goto next;
	}
      }
    }
  next:
    ;
  }
  return 0;
}

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


bool IsCoprime(int a, int b)
{
	while (a > 0 && b > 0)
	{
		if (a < b) swap(a, b);
		a %= b;
	}
	if (a == 1 || b == 1) return true;
	return false;
}


char get(int a, int b, char c)
{
	for (int i = 0; i < 26; i++)
	{
		if ((a * i + b) % 26 == c - 'a') return char(i + 'a');
	}
}


int main()
{
	int n;
	string cip;
	string dec;

	cin >> n;
	cin.get();

	while (n--)
	{
		getline(cin, cip);
		dec = cip;

		for (int a = 0; a < 26; a++)
		{
			if (!IsCoprime(a, 26)) continue;
			for (int b = 0; b < 26; b++)
			{
				for (int i = 0; i < cip.size(); i++)
				{
					dec[i] = get(a, b, cip[i]);
				}
				if (dec.find("that") != -1 || dec.find("this") != -1)
				{
					cout << dec << endl;
				}
			}
		}
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

map<char, char> computeMap(int a, int b) {
	map<char, char> res;
	for (int x = 0; x < 26; x++) {
		int y = (a * x + b) % 26;
		res[y + 'a'] = x + 'a';
	}

	return res;
}

string decode(string str, map<char, char> m) {
	for (auto &c : str) {
		c = isalpha(c) ? m[c] : c;
	}
	return str;
}

string solve(string str) {
	for (int a = 0; a < 26; a++) {
		for (int b = 0; b < 26; b++) {
			if (__gcd(a, 26) != 1) continue;
			map<char, char> m = computeMap(a, b);
			string decoded = decode(str, m);
			if (decoded.find("that") != string::npos || 
				decoded.find("this") != string::npos) {
				return decoded;
			}
		}
	}
	return "hoge";
}

int main(void) {
	int N;
	cin >> N;
	cin.get();

	for (int i = 0; i < N; i++) {
		string str;
		getline(cin, str);
		cout << solve(str) << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const string keyword[] = {"that", "this" };

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

int main()
{
//	cut here before submit 
//	freopen ("testcase.AC", "r", stdin );
	int n;
	string sn = "";
	getline (cin, sn );
	stringstream ssn (sn );
	ssn >> n;
//	scanf ("%d", &n );
	rep (i, n ){
		string str = "";
		getline (cin, str );
		int m = str.length();
		string res = "";
		for (int a = 1; a <= 26; a++ ){
			if (__gcd (a, 26 ) != 1 ) continue;
			for (int b = 0; b <= 26; b++ ){
				string s = str;
				rep (i, m ){
					if (isalpha(s[i] ) ){
						char c = (char)(affine (a, b, (int)(s[i] - 'a') ) + 'a' );
						if (isalpha (c ) ){
							s[i] = c;
						} // end if
					} // end if
				} // end rep
//				cerr << "s: " << s << endl;
				rep (i, 2 ){
					if (s.find (keyword[i] ) != string::npos ){
						res = s;
						break;
					} // end if
				} // end rep
				if (!res.empty() ) break;
			} // end for
			if (!res.empty() ) break;
		} // end for
		cout << res << endl;
	} // end loop
		
	return 0;
}

C++: #include<iostream>
#include<map>
using namespace std;
map<int,int>M;
string s;
string t[]={"that","this"};
main()
{
	int n;cin>>n;cin.ignore();
	for(;n--;)
	{
		getline(cin,s);
		bool f=0;
		for(int a=1;!f&&a<26;a+=2)for(int b=0;!f&&b<26;b++)
		{
			map<int,int>M;
			if(a==13)continue;
			for(int z=0;z<26;z++)M[(a*z+b)%26]=z+'a';
			string S="";
			for(int i=0;i<s.size();i++)S+=(s[i]>='a'&&s[i]<='z'?M[s[i]-'a']:s[i]);
			for(int i=0;!f&&i<2;i++)
			{
				for(int j=0;!f&&j+t[i].size()<=S.size();j++)
				{
					if(S.substr(j,t[i].size())==t[i])
					{
						cout<<S<<endl;
						f=1;
					}
				}
			}
		}
	}
}

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

using namespace std;

string Affine(string S)
{
	vector<int> F(26);

	for (int i = 0; i < 26; i++) // alpha
	{
		for (int j = 0; j < 26; j++) // beta
		{
			for (int k = 0; k < 26; k++) // gamma
			{
				F[k] = (i * k + j) % 26;
			}
			
			string T = S;

			for (int k = 0; k < S.size(); k++)
			{
				if (islower(S[k]))
				{
					T[k] = F[S[k] - 97] + 97;
				}
				else
				{
					T[k] = S[k];
				}
			}

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

	return "";
}

int main()
{
	int n; string S;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		getline(cin, S);

		cout << Affine(S) << endl;
	}
	
	return 0;
}