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 <vector>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
using namespace std;
#define M_PI 3.141592
#define toRad 2.0*M_PI/360.0
#define inin(x) int x;cin>>x;
#define all(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" "<<x<<endl;
int euclid(int a, int b)
{
	if (a < b)swap(a, b);
	if (b == 0)return a;
	else return euclid(b, a%b);
}
char hoge(int a)
{
	return 'a' + a;
}
bool check(string a)
{
	if (a.find("that", 0) != string::npos || a.find("this", 0) != string::npos)
	{
		return true;
	}
	return false;
}
int main()
{
	int n;
	cin >> n; cin.ignore();
	while (n--)
	{
		string str;
		bool ok = true;
		getline(cin, str);
		for (int a = 0; ok; a++)
		{
			if (euclid(a, 26) != 1)continue;
			for (int b = 0; ok&& b < 26; b++)
			{
				string ans = "";
				for (int i = 0; i < str.size(); i++)
				{
					if (str[i] == ' ') {
						ans += " "; continue;
					}
					for (int y = 0; y < 26; y++)
					{
						int num = (a*y + b) % 26;
						if (hoge(num) == str[i])
						{
							ans += hoge(y);
							break;
						}
					}
				}
				if (check(ans))
				{
					cout << ans << endl;
					ok = false;
				}
			}
		}
	}
}

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

char encode(char x,int a,int b){
	return ( ( a * (x-'a') + b) % 26 ) + 'a';
}

char decode(char x, int a, int b){
	int t = ( x - 'a') - b;
	while( (t%a) != 0 ) t += 26;
	return (t/a) % 26 + 'a';
}

string encode(string s, int a, int b){
	for(int i =0 ; i<(int)s.size() ; ++i )
		if( s[i] >= 'a' && s[i] <= 'z' )
			s[i] = encode( s[i] , a , b );
	return s;
}

string decode(string s, int a, int b){
	for(int i =0 ; i<(int)s.size() ; ++i )
		if( s[i] >= 'a' && s[i] <= 'z' )
			s[i] = decode( s[i] , a , b );
	return s;
}

int main(){
	int n=1;
	int a[12] = {1,3,5,7,9,11,15,17,19,21,23,25};
	
	string str, s;
	scanf("%d ", &n);
	
	for(int i=0 ; i<n ; ++i){
		bool flag = false;
		getline( cin , str );
		char foo[257];
		//gets( foo );
		str = foo;

		for(int i=0 ; i<12 ; ++i){
			for(int j=0 ; j<26 ; j++){
				s = decode( str , a[i] , j );
				if( s.find("this") != string::npos || s.find("that") != string::npos ){
					flag = true;
					break;
				}
			}
			if( flag ) break;
		}
		printf("%s\n" , s.c_str() );
	} 
}

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

string AffineCipher(string s, int a, int b){
	for (int i = 0; i < s.size(); ++i){
		if (s[i] >= 'a' && s[i] <= 'z')
			s[i] = (a*(s[i] - 'a') + b) % 26 + 'a';
	}
	return s;
}

string DeAffine(string s, int a, int b){
	int t;
	for (int i = 0; i < s.size(); ++i){
		if (s[i] >= 'a' && s[i] <= 'z'){
			t = (((s[i] - 'a') - b) * a);
			while(t<0)
				t+=26;
			s[i] = t % 26 + 'a';
		}
	}

	return s;

}

int main(){
	int n, b;
	int a[12] = { 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25 };
	string s,t;
	string key1, key2;
	cin >> n;cin.ignore();

	for (int j = 0; j < n; ++j){
		
		getline(cin,s);
		
		for (int i = 0; i < 12;++i){

			for (b = 1; b <= 26; ++b){
				
				t = DeAffine(s,a[11-i],b);
				
				if (t.find("this") != -1 || t.find("that") != -1){
					cout << t << endl;
				}
			}
		}
	}
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
	int n , alpha , beta;
	string s,org;
	cin >> n;
	cin.ignore();
	for(int i=0;i<n;++i){
		getline(cin , s);
		org=s;
		while(1){
				for(alpha=1;alpha<26;++alpha){
						if(alpha){
							if(26%alpha==0) continue;
						}
					for(beta=1;beta<=26;++beta){
						for(int k=0;k<26;++k){
							if((s[0]-'a')==(alpha*k+beta)%26){
								for(int l=0;l<s.length();++l){
									for(int m=0;m<26;++m){
										if(isalpha(s[l])){
											if((s[l]-'a')==(alpha*m+beta)%26){
											org[l]=m+'a';
											}
										}
									}
								}
								if(org.find("this" ,0)!=string::npos || org.find("that" , 0)!=string::npos) goto result;
							}
						}
					}
					
				}
				
		}
		result:;
		cout << org << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
#include <set>
#include <map>

using namespace std;

class AffineCipher
{
public:
	string decode (string, vector <int> );
	vector<int> make_alpha (void);
private:
	int gcd (int, int );
	bool decide_variable (int, int, string );
	bool check_code (string );
};

int AffineCipher::gcd (int a, int b )
{
	if (a > b){
		swap(a,b);
	} // end if
	while (b % a != 0 ){
		b = b % a;
		if (a > b ){
			swap(a, b );
		} // end if
	} // end while

	return a;
}
bool AffineCipher::decide_variable (int a, int b, string str )
{
	set <char> code; 
	set <char> source;
	int i;

	for (i = 0; i < str.length(); ++i ){
		if (isalpha(str[i]) ){
			source.insert (str[i] );
		} // end if
	} // end for
	set <char>::iterator it = source.begin();

	for (; it != source.end(); ++it ){
		char c = (a*((*it) - 'a' ) + b ) % 26 + 'a';
		if (code.count (c) ){
			return false;
		}else{
			code.insert (c);
		} // end if
	} // end for

	return true;
}
bool AffineCipher::check_code (string str )
{
	const string keyword[] = { "this", "that" };

	for (int i = 0; i < sizeof(keyword)/sizeof(keyword[0]); ++i){
		if (str.find(keyword[i] ) != string::npos ){
			return true;
		} // end if
	} // end for

	return false;
}
string AffineCipher::decode (string str, vector <int> alpha )
{
	int len = str.length();
	int a, b;
	multimap <int, int> table;
 	int i;

	for (i = 0; i < alpha.size(); ++i){		
		a = alpha[i];
		for (b = 0; b < 26; ++b){
			if (!decide_variable (a, b, str ) ){
				continue;
			}else{
				table.insert (make_pair (a, b ) );
			} // end if
		} // end for
	} // end for

	string res = "";
	multimap <int, int>::iterator it = table.begin();
	for (; it != table.end(); ++it){
		a = (*it).first;
		b = (*it).second;
		res = "";
		for (i = 0; i < len; ++i){
			char c = 0;
			if (isalpha(str[i] ) ){
				c = (a*(str[i] - 'a' ) + b ) % 26 + 'a';
			}else{
				c = str[i];
			} // end if
			res += c;
		} // end for
		if (!check_code (res ) ){
			continue;
		}else{
			break;
		} // end if
	} // end for

	return res;
}
vector <int> AffineCipher::make_alpha (void)
{
	vector <int> alpha;
	int i;

	for (i = 1; i < 26; ++i){
		if (gcd(i, 26 ) == 1 ){
			alpha.push_back(i);
		} // end if
	} // end for

	return alpha;
}
	
int main()
{
	AffineCipher AC;
//	cut here before submit 
//	freopen("testcase.ac", "r", stdin);
	string str = "";
	int n;

	getline (cin, str );
	stringstream ssn(str);
	ssn >> n;
	
	vector <int> alpha = AC.make_alpha();
	int i;

	for (i = 0; i < n; ++i){
		string res = "";
		getline (cin, str );
		res = AC.decode (str, alpha );
		cout << res << endl;
	} // end for
		
	return 0;
}