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>
#include <cctype>
#include <cstdlib>
using namespace std;

char letters[] = {
	'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
	'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
	's', 't', 'u', 'v', 'w', 'x', 'y', 'z',' '
};

int index(char c){
	if(c == ' ') return 26;
	return (int)c - 97;
}

int affine(int a, int b, char c){
	return (a * index(c) + b) % 26;
}

int raffine(int a, int b, char c){
	if(c == ' ') return 26;
	int k = 0;
	for(;;k++){
		if(((index(c) - b) + k * 26) % a == 0)
			break;
	}
	return (((index(c) - b) + k * 26) / a) % 26;
	return c;
}

bool is_sosu(int a){
	for(int i = 2; i < a; i++){
		if(a % i == 0) return false;
	}
	return true;
}

bool find_s(string s, string t, int a, int b){
	string t2;
	for(string::iterator iter = t.begin(); 
		iter != t.end(); iter++)
	{
		t2.push_back(letters[affine(a,b,*iter)]);
	}
	string::iterator iter = search(s.begin(), s.end(), t2.begin(), t2.end());
	if(iter != s.end()) return true;
	else return false;
}

int main(){
	string s;
	string t1("that"), t2("this");
	string s1;
	int n;
	getline(cin, s1);
	n = atoi(s1.c_str());
	for(int i = 0; i < n; i++){
		getline(cin, s);
		int a = 2, b = 0;
		int c = 0;
		for(;;a++){
			b = 0;
			if(is_sosu(a)){
				for(; b < 26; b++){
					if(find_s(s,t1,a,b) || find_s(s,t2,a,b)){
						c = 1;
						break;
					}
				}
			}
			if(c) break;
		}
		for(string::iterator iter = s.begin();
			iter != s.end(); iter++)
		{
			cout << letters[raffine(a, b, *iter)];
		}
		cout << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<string.h>


#define MAX_STR 257
#define ALFA_NUM 26

using namespace std;

int gcd(int);

int main(){

	int n;
	char str[MAX_STR],fstr[MAX_STR];
	bool flag;
	
	scanf("%d",&n);
	
	for(int m=0;m<n;m++){
		flag=true;
		//fgetsの入力がsizeof(str)を超えたら捨てる
		fflush(stdin);
				
		fgets(str,sizeof(str),stdin);
		
		
		for(int i=0;i<100;i++){
			if(gcd(i)==1){
				for(int j=0;j,26;j++){
				
					memset(fstr,'\0',sizeof(fstr));
					
					for(int k=0;str[k]!='\0' && k<sizeof(str);k++){
						
						if(str[k]!='\n' && str[k]!=' '){
							fstr[k]=((i*(str[k]-'a')+j)%ALFA_NUM)+'a';
						}
						else if(str[k]!='\n'){
							fstr[k]=str[k];
						}					
					}
					
					if(strstr(fstr,"that")!=NULL||strstr(fstr,"this")!=NULL){
						printf("%s\n",fstr);
						flag=false;
					}
				}
			}
		}
	}
}

int gcd(int n){
	int temp,m;
	m=ALFA_NUM;
	if(n>m){
		temp=n;
		n=m;
		m=temp;
	}
	while(1){
		if(n==0){
			return m;
		}
		temp=n;
		n=m%n;
		m=temp;
	}
}

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

int main()
{
	int n;
	std::cin >> n;
	std::cin.ignore();

	while( n-- )
	{
		std::string s;
		std::getline( std::cin, s );

		std::string t( s.size(), ' ' );

		for( int a = 1; a < 26; a += 2 )
		{
			if( a == 13 )
				continue;

			for( int b = 0; b != 26; ++b )
			{
				for( int i = 0; i != s.size(); ++i )
				{
					if( s[i] >= 'a' && s[i] <= 'z' )
					{
						int g = s[i] - 'a';

						t[i] = ( a * g + b ) % 26 + 'a';
					}
				}

				if( t.find( "this" ) != std::string::npos || t.find( "that" ) != std::string::npos )
					goto end;
			}
		}

end:;

		std::cout << t << std::endl;
	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,a) loop(i,0,a)
string m,p;
int main(){
    int n;cin>>n;
    cin.ignore();
    while(n--){
        getline(cin,m);
        p.resize(m.size());
        for(int a=1;;a++){
            if(__gcd(a,26)!=1) continue;
            rep(b,26){
                char dic[256];
                rep(from,26){
                    int to=from*a+b;
                    to%=26;
                    dic[to+'a']=from+'a';
                }
                dic[' ']=' ';
                rep(i,m.size()){
                    p[i]=dic[(int)m[i]];
                }
                if(p.find("this")==(size_t)-1&&
                   p.find("that")==(size_t)-1) continue;
                cout<<p<<endl;
                goto end;
            }
        }
    end:;
    }
}

C++: #include<iostream>
#include<string>
using namespace std;
string str,tmp;
int n,i,j;
string change(string);
bool check(string);
int main(){
	cin>>n;
	cin.ignore();
	while(n--){
		getline(cin,str);
		tmp=str;
		for(i=0;i<=1000;i++){
			for(j=0;j<=1000;j++){
				//cout<<i<<" "<<j<<endl;
				str=tmp;
				str=change(str);
				if(check(str)){
					cout<<str<<endl;
					i=j=9999;
				}
			}
		}
	}
}
string change(string st){
	for(int I=0;I<(int)st.size();I++){
		if('a'<=st[I]&&st[I]<='z'){
			st[I]= ((st[I]-'a')*i+j)%26 + 'a';
		}
	}
	return st;
}
bool check(string st){
	//cout<<st<<endl;
	for(int I=0;I<(int)st.size()-3;I++){
		if(st.substr(I,4)=="this")return true;
		if(st.substr(I,4)=="that")return true;
	}
	return false;
}

C++: #include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <stdlib.h>
#include <ctime>
#include <list>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#define INF 10000000
#define I64 long long int
#define rep(i) for(I64 i=0;;++i)
#define repn(i,n) for(I64 i=0;i<(n);++(i))
using namespace std;

typedef pair<string, int> P;

bool coprime(int a, int b){
	int r, temp;
	if(a < b){
		temp = a;
		a = b;
		b = temp;
	}
	do{
		r = a % b;
		a = b;
		b = r;
	}while(r);
	if(a == 1) return true;
	else return false;
}

int main(){
	char t[26];

	int n;
	cin >> n;

	scanf("%*c");

	repn(i, n){
		string input;
		getline(cin, input);
		int len = input.size();

		bool flag = false;
		rep(a){
			if(coprime(26, a+1)){
				repn(b, 26){
					string res = "";
					repn(r, 26){
						t[r] = ((a+1) * r + b) % 26 + 'a';
					}
					repn(j, len){
						if(input[j] == ' ') res += ' ';
						else{
							repn(k, 26){
								if(input[j] == t[k]){
									res += k + 'a';
									break;
								}
							}
						}
					}
					if(res.find("this") != string::npos || res.find("that") != string::npos){
						cout << res << endl;
						flag = true;
						break;
					}
				}
				if(flag) break;
			}
			if(flag) break;
		}
	}
}

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++)
				{
					if (cip[i] == ' ') continue;
					dec[i] = get(a, b, cip[i]);
				}
				if (dec.find("that") != -1 || dec.find("this") != -1)
				{
					cout << dec << endl;
				}
			}
		}
	}

	return 0;
}