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<algorithm>
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
vector<int> in;
vector<string> list = {"+","-","*"};
vector<pair<int,int>> ll;
void gen(int,int,int);
void init(){
ll.push_back(make_pair(0,3));
ll.push_back(make_pair(1,4));
ll.push_back(make_pair(0,2));
ll.push_back(make_pair(1,3));
ll.push_back(make_pair(2,4));
for(int i=0;i<list.size();i++){
for(int j=0;j<list.size();j++){
for(int k=0;k<list.size();k++){
gen(i,j,k);
}
}
}
}
vector<string> cal_list;
void gen(int ii,int jj,int kk){
for(long long i=0;i<(1<<ll.size());i++){
int l[5]={},e[5]={};
for(int j=0;j<(int)ll.size();j++){
if(i&(1<<j)){
l[ll[j].first]++;
e[ll[j].second]++;
}
}
string tmp = "";
string abc[] = {"a","b","c","d"};
for(int i=0;i<5;i++){
for(int j=0;j<e[i];j++){
tmp += ")";
}
if(i==1)tmp+=list[ii];
if(i==2)tmp+=list[jj];
if(i==3)tmp+=list[kk];
for(int j=0;j<l[i];j++){
tmp += "(";
}
if(i!=4){
tmp += abc[i];
}
}
cal_list.push_back(tmp);
}
}
string conv(string s){
stack<char> st;
s = "(("+s+"))";
string res;
for(int i=0;i<s.size();i++){
switch(s[i]){
case '(':
st.push(s[i]);
break;
case ')':
while(1){
char tmp = st.top(); st.pop();
if(tmp=='(')break;
res += tmp;
}
break;
case '+':
case '-':
while(1){
char tmp = st.top();st.pop();
if(tmp=='*'||tmp=='+'||tmp=='-'){
res+= tmp;
}else{
st.push(tmp);
break;
}
}
st.push(s[i]);
break;
case '*':
while(1){
char tmp = st.top();st.pop();
if(tmp=='*'){
res+= tmp;
}else{
st.push(tmp);
break;
}
}
st.push(s[i]);
break;
default:
res += s[i];
}
}
return res;
}
int cal_t(char a,int x,int y){
switch(a){
case '+':return x+y;
case '-':return x-y;
case '*':return x*y;
}
return 0;
}
int cal(string s,vector<int>& in){
stack<int> st;
for(int i=0;i<s.size();i++){
switch(s[i]){
case 'a':st.push(in[0]);break;
case 'b':st.push(in[1]);break;
case 'c':st.push(in[2]);break;
case 'd':st.push(in[3]);break;
default:
int b = st.top();st.pop();
int a = st.top();st.pop();
int c = cal_t(s[i],a,b);
st.push(c);
}
}
return st.top();
}
string convert(string s,vector<int>& in){
string res="";
for(int i=0;i<s.size();i++){
if(s[i]=='a'){
res += to_string(in[0]);
}else if(s[i]=='b'){
res += to_string(in[1]);
}else if(s[i]=='c'){
res += to_string(in[2]);
}else if(s[i]=='d'){
res += to_string(in[3]);
}else{
res += s[i];
}
}
return res;
}
string solve(){
//cout<<cal_list.size()<<endl;
for(int i=0;i<cal_list.size();i++){
sort(in.begin(),in.end());
string tmp = conv(cal_list[i]);
do{
int tt = cal(tmp,in);
//cout<<tt<<" "<<convert(cal_list[i],in)<<" "<<tmp<<endl;
if(tt==10){
//cout<<cal_list[i]<<" "<<conv(cal_list[i])<<endl;
return convert(cal_list[i],in);
}
}while(next_permutation(in.begin(),in.end()));
}
return "0";
}
int main(){
init();
bool j;
while(1){
j=false;
in.clear();
for(int i=0;i<4;i++){
int tmp;
cin>>tmp;
if(tmp!=0)j=true;
in.push_back(tmp);
}
if(!j)break;
cout<<solve()<<endl;
}
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
typedef complex<double> P;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 29;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };


int gcd( int n, int m ) {
	if ( m == 0 ) {
		return n;
	}
	return gcd( m, n % m );
}

string Affine(string str, int a, int b) {
	string res = "";
	for ( int i = 0; i < str.size(); i++ ) {
		if ( str[ i ] >= 'a' && str[ i ] <= 'z' ) {
			char y = str[ i ] - 'a';
			res += ( char ) ( ( a * y + b ) % 26 ) + 'a';
		}
		else {
			res += str[ i ];
		}
	}
	return res;
}

int main() {
	int n;
	scanf( "%d\n", &n );
	while ( n-- ) {
		string str;
		getline( cin, str );
		for ( int i = 0; i < 100; i++ ) {
			if ( gcd( i, 26 ) != 1 ) {
				continue;
			}
			for ( int j = 0; j < 26; j++ ) {
				string s = Affine( str, i, j );
				if ( s.find( "that" ) != string::npos || s.find( "this" ) != string::npos ) {
					printf( "%s\n", s.c_str() );
					goto fin;
				}
			}
		}
	fin:;
	}
	return 0;
}

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

int main(){
  int n;
  (cin >> n).ignore();
  while(n--){
    string str;
    getline(cin,str);
    bool flg = false;
    for(int i=0;i<26;i++){
      for(int j=0;j<26;j++){
	string tmp = str;
	for(int k=0;k<tmp.size();k++){
	  if(tmp[k] != ' ') tmp[k] = 'a'+(((tmp[k]-'a')*i+j) % 26);
	}
	if(tmp.find("this")!=string::npos || tmp.find("that")!=string::npos){
	  cout << tmp << endl;
	  flg = true;
	  break;
	}
      }
      if(flg) break;
    }
  }
}

C++: #include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
char c[257];
char d[257];
bool use[26];
int gcd(int a,int b){
	while(a){
		b%=a;
		int val=b;
		b=a;
		a=val;
	}
	return b;
}
int main(){
	int a;
	scanf("%d ",&a);
	while(a--){
		cin.getline(c,257);
		int t=strlen(c);
		for(int i=1;i<26;i++){
			for(int j=1;j<26;j++){
				bool ok=false;
				if(gcd(i,26)>1)goto dame;
				for(int k=0;k<26;k++)use[k]=false;
				for(int k=0;k<26;k++){
					if(use[(i*k+j)%26])goto dame;
					else use[(i*k+j)%26]=true;
				}
				for(int k=0;k<t;k++){
					if(c[k]<='z'&&c[k]>='a'){
						d[k]=(i*(c[k]-'a')+j)%26+'a';
					}else{
						d[k]=c[k];
					}
				}
				for(int k=0;k<t-3;k++){
					if(d[k]=='t'&&d[k+1]=='h'){
						if(d[k+2]=='a'&&d[k+3]=='t')ok=true;
						if(d[k+2]=='i'&&d[k+3]=='s')ok=true;
					}
				}
				if(ok){
					printf("%s\n",d);
					goto owari;
				}
				dame:;
			}
		}
		owari:;
	}
}