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 <bits/stdc++.h>
using namespace std;

using db = double;
using ll = long long;
using vi = vector <int>;
#define op operator
#define pb push_back

string trans(string s, int a, int b) {
	for(auto &c : s) if(isalpha(c)) {
		int t = c - 'a';
		t = (t * a + b) % 26;
		c = t + 'a';
	}
	return s;
}

int main() {
	ios :: sync_with_stdio(0);

	int n; cin >> n;
	string s; getline(cin, s);
	while(n --) {
		getline(cin, s);
		for(int a = 1; a < 26; a ++)
			for(int b = 0; b < 26; b ++) if(__gcd(a, 26) == 1) {
				string t = trans(s, a, b);
				bool f = 0;
				for(int i = 0; i < t.size(); i ++)
					if(t.substr(i, 4) == "this" || t.substr(i, 4) == "that")
						f = 1;
				if(f) {
					cout << t << '\n';
					goto done;
				}
			}
		done: ;
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
#include <complex>
#include <cstring>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

char change(int a,int b, char c){
  if(c == ' ')return c;
  return 'a' + (a * (c - 'a') + b) % 26;
}
int main(void){
  int a[] = {1,3,5,7,9,11,15,17,19,21,23,25,0};
  int n; cin>>n; cin.ignore();
  string str,str_cp,sp = " ";
  
  while(getline(cin,str)){
    str = str_cp = sp + str + sp;
    bool f = false;
    for(int i = 0 ; !f && a[i] ; i ++){
      for(int b = 0 ; !f && b < 26 ; b ++){
	for(int j = 0 ; j < str.length() ; j ++){
	  str[j] = change(a[i],b,str[j]);
	}
	if(str.find(" that ") != string::npos
	   || str.find(" this ") != string::npos){
	  f = true;
	  break;
	}

	str = str_cp;
      }
    }
    cout<<str.substr(1,str.length() - 2)<<endl;
  }
}

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

int main(){
	int n;
	string str;
	bool output;
	int code;
	int str1[4] = {19, 7, 8, 18};
	int str2[4] = {19, 7, 0, 19};
	
	cin >> n;
	
	getline(cin, str);
	for(int i = 0; i < n; i++){
		getline(cin, str);
		
		output = false;
		
		for(int a = 0; !output && a < 26; a++){
			for(int b = 0; !output && b < 26; b++){
				for(int p = 0; !output && p < str.size() - 4; p++){
					for(int c = 0; !output && c < 4; c++){
						code = (a * (str[p + c]-97) + b) % 26;
						if(code != str1[c]) break;
						else if(c + 1 == 4){
							output = true;
							for(int P = 0; P < str.size(); P++){
								if(str[P] != ' ') cout << (char)((a * (str[P]-97) + b) % 26 + 97);
								else cout << " ";
							}
							cout << endl;
						}
					}
					for(int c = 0; !output && c < 4; c++){
						code = (a * (str[p + c]-97) + b) % 26;
						if(code != str2[c]) break;
						else if(c + 1 == 4){
							output = true;
							for(int P = 0; P < str.size(); P++){
								if(str[P] >= 97 && str[P] <= 122) cout << (char)((a * (str[P]-97) + b) % 26 + 97);
								else if(str[P] == ' ') cout << " ";
							}
							cout << endl;
						}
					}
				}
			}
		}
	}
	
	return 0;
}

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

using namespace std;

/** Problem0040 : Affine Chipher **/
int main()
{
	string tmp, str;
	int n;
	
	cin >> n;
	cin.ignore();
	for (int i=0; i<n; i++) {
		getline(cin, tmp);
		string tt = tmp;
		for (int alpha=0; alpha<1000; alpha++) {
			for (int beta=0; beta<26; beta++) {
				for (int j=0; j<tt.length(); j++)
					if (tt[j]!=' ') tt[j] = 'a'+((tmp[j]-'a')*alpha+beta)%26;
				if (tt.find("that")!=-1 || tt.find("this")!=-1) {
					cout << tt << endl;
					goto end;
				}
			}
		}
	end: ;
	}
	return 0;
}

C++: #include<iostream>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cmath>
using namespace std;
int inf = 1000000000;

char affine(char c, int a, int b){
  int x = c - 'a';
  int y = ( a * x + b ) % 26;
  char r = 'a' + y;
  return r;
}

int main(){

  int n;
  cin >> n;
  cin.ignore();
  for(int l=0; l<n; l++){
    string s;
    getline(cin, s);

    for(int i=0; i<50; i++){
      if( i %= 2 == 0 || i %= 13 == 0 ) continue;
      for(int j=0; j<50; j++){
        string t = "";
        for(int k=0; k<s.size(); k++){
          if( 'a' <= s[k] && s[k] <= 'z' ) t += affine(s[k], i, j);
          else t += s[k];
        }
        for(int k=0; k<t.size()-4; k++){
          if( (t[k] == 't' && t[k+1] == 'h' && t[k+2] == 'a' && t[k+3] == 't') || (t[k] == 't' && t[k+1] == 'h' && t[k+2] == 'i' && t[k+3] == 's') ) cout << t << endl;
        }
      }
    }

  }


  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

string change(string s,int a,int b){
	string ret(s);
	rep(i,0,ret.size()){
		int y=ret[i]-'a';
		y=(a*y+b)%26;
		ret[i]='a'+y;
	}
	return ret;
}

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

int main(){
	int n;
	cin>>n;
	string str[2]={"that","this"};
	rep(i,0,n){
		string s;
		bool f=0;
		getline(cin,s);
		rep(a,0,26){
			if(gcd(a,26)!=1) continue;
			rep(b,0,26){
				string t;
				t=change(s,a,b);
				rep(j,0,2){
					if(t.find(str[j]) != string::npos){
						o(t); f=1; break;
					}
				}
				if(f) break;
			}
			if(f) break;
		}

	}
}

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

int main() {
  int n;
  cin >> n;
  cin.ignore();
  vector<string> s(n);
  for (int i = 0; i < n; ++i) {
    getline(cin, s[i]);
  }

  for (int i = 0; i < n; ++i) {
    for (int a = 0; a < 26; ++a) {
      for (int b = 0; b < 26; ++b) {
        string s2 = s[i];
        for (int j = 0; j < s2.size(); ++j) {
          if (s2[j] == ' ') {
            continue;
          }
          s2[j] = (a * (s2[j] - 'a') + b) % 26 + 'a';
        }

        if (s2.find("this") != s2.npos || s2.find("that") != s2.npos) {
          s[i] = s2;
        }
      }
    }
  }

  for (int i = 0; i < n; ++i) {
    cout << s[i] << endl;
  }
}

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 = 0; 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;
}