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 <sstream>
#include <string>
#include <vector>
using namespace std;
typedef vector <string> vs;
#define REP(i,n) for (int i=0; i<n; i++)
string A2Z="abcdefghijklmnopqrstuvwxyz";
struct affine_key{
	int a;
	int b;
};

string decode(string &L1, string &L2, string &msg){
	int n=msg.size();
	string s="";
	REP(i,n){
		char c=msg[i];
		if (c>='a' && c<='z'){
			string::size_type index=L1.find(c);
			s += L2[index];
		}else
			s += c;
	}
	return s;
}

string affine(string &msg, affine_key &key){
	string s="", s2;
	REP(i,26){
		int it=(i*key.a+key.b+26)%26;
		s += A2Z[it];
	}
	return decode(A2Z, s, msg);
}

string rot(string &msg, int a){
	if (a==0) return msg;
	while (a<0)
		a+= 26;
	a %= 26;
	string s = A2Z.substr(a)+A2Z.substr(0,a);
	return decode(A2Z, s, msg);
}

affine_key find(string &msg){
	char c0='t';
	affine_key key;
	for (int i=1; i<26; i+=2){
			key.a=i;
			key.b=0;
		string x=affine(msg, key);
		int a = c0-x[0];
		if (a<0) a += 26;
		x = rot(x,a);
		if (x=="this" || x=="that"){
			key.b=a;
			return key;
		}
	}
	key.a=-1;
	key.b=-1;
	return key;
}

vs split(const string &text, char delim=' '){
    int p1 = 0, p2 = 0;
    vs tokens;
 
    for (int i=0; i<(int)text.size(); i++)
        if (text[i] == delim){
            p2 = i;
            tokens.push_back(text.substr(p1, p2 - p1));
            p1 = p2 + 1;
        }
    tokens.push_back(text.substr(p1));
    return tokens;
}

int main(void){
	int n;
	string msg;
	cin>>n;
	getline(cin, msg);
	REP(i,n){
		getline(cin, msg);
		vs word = split(msg);
		affine_key key;
		REP(i, word.size())
			if (word[i].size()==4){
				key = find(word[i]);
				if (key.a != -1) break;
			}
			cout<<affine(msg, key)<<endl;
	}
}

C++: #include<iostream>
#include<string>
#include<stdio.h>
#include<ctype.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string a;
	char b[500];
	for(int u=0;u<n;u++){
		cin.ignore();
		getline(cin,a);
		int c=0;
		bool end=false;
		while(true){
		for(int i=0;i<a.size();i++){
			if(isalpha(a[i])!=0)
			    b[i]=((a[i]-'a')*c)%26+'a';
			else
				b[i]=a[i];
		}
		int d=0;
		while(true){
			for(int i=0;i<a.size()-3;i++){
				if(b[i]=='t'&&b[i+1]=='h'&&((b[i+2]=='i'&&b[i+3]=='s')||(b[i+2]=='a'&&b[i+3]=='t'))){
					end=true;
					break;
				}
			}
			if(end==true)
				break;
			for(int i=0;i<a.size();i++){
				if(isalpha(b[i])!=0){
					b[i]++;
					if(b[i]>'z')
						b[i]='a';
				}
			}
			d++;
			if(d==100)
				break;
		}
		if(end==true)
			break;
		c++;
		}
		for(int i=0;i<a.size();i++)
			cout<<b[i];
		cout<<endl;
	}
	return 0;
}

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

int alpha,beta;

char f(int c) {
    if(c == ' ') return ' ';
    return (char)(((alpha*(c-'a')+beta)%26)+'a');
}

int main() {
    int n;
    string in;
    cin>>n;
    cin.ignore();
    while(n--) {
        getline(cin, in);
        for(alpha = 2; alpha<26000; ++alpha) {
            if(26%alpha == 0) continue;

            for(beta = 0; beta <26; ++beta) {
                string ci = in;
                for(int i=0; i<ci.length(); ++i)
                    ci[i] = f(ci[i]);


                if(ci.find("this") != string::npos || ci.find("that") != string::npos) {
                    cout<<ci<<endl;
                    goto END;
                }
            }
        }
    END:;
    }
}

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

int main(){
	int n;
	char str[257] = {}, str_c[257], len;
	cin >> n;
	getchar();
	for (int m = 0; m < n; m++){
		gets(str);
		len = strlen(str);
		//printf("%d\n", len);
		for (int i = 0; i < 26; i++){
			/*if (i % 2 == 0 || i % 13 == 0) continue;*/
			for (int j = 0; j < 26; j++){
				for (int k = 0; k <= len; k++){
					if (isalpha(str[k])){
						str[k] -= 'a';
						str_c[k] = (str[k] * i + j) % 26 + 'a';
						str[k] += 'a';
					}
					else{
						str_c[k] = str[k];
					}
				}
				if (strstr(str_c, "this") || strstr(str_c, "that")){
					printf("%s\n", str_c);
					return 0;
				}
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <ctype.h>
#include <sstream>
using namespace std;

bool in_word (string s1, string s2) {
    stringstream ss;
    ss << s1;
    while (ss >> s1) {
        if (s1 == s2) return true;
    }
    return false;
}

string affin (string str, int a, int b) {
    int tmp[26];
    for (int i = 0; i < 26; i++) tmp[i] = -1;
    for (int i = 0; i < str.size(); i++) {
        if (!(isalpha(str[i]))) continue;
        int s = str[i] - 'a';
        int g = (a * s + b) % 26;
        if (tmp[g] != -1 && tmp[g] != s) return "";
        else if (tmp[g] == -1) tmp[g] = s;
        str[i] = (char)(g + 'a');
    }
    
    return str;
}

int main ()
{
    int n;
    cin >> n;
    string str;
    getline(cin, str);
    while (n--) {
        getline(cin, str);
        for (int i = 0; i <= 26; i++) {
            for (int j = 0; j <= 26; j++) {
                string tmp = affin(str, i, j);
                if (tmp == "") continue;
                if (in_word(tmp, "this") || in_word(tmp, "that")) {
                    cout << tmp << endl;
                    goto escape;
                }
            }
        }
    escape:;
    }
    
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<map>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

bool func(int a,int b,int y,int fy){
	return fy==(a*y+b)%26;
}

int func(int a,int b,int y){
	return (a*y+b)%26;
}

map<char,int> mp;
map<int,char> rever;

int main(){
	rep(i,26){
		int ch=(int)'a';
		mp[(char)(ch+i)]=i;
		rever[i]=(char)(ch+i);
	}
	int n;
	cin>>n;
	rep(l,n){
		string s,temp="";
		if(l==0)cin.ignore();
		getline(cin,s);
		vector<string> vec;
		vector<int> flg;
		rep(i,s.size()+1){
			if(s[i]==' ' || i==s.size()){
				if(temp.size()==4)flg.push_back(vec.size());
				vec.push_back(temp);
				temp="";
			}else{
				temp+=s[i];
			}
		}
		int alpha,beta;
		rep(i,flg.size()){
			alpha=beta=-1;
			rep(a,27){
				rep(b,27){
					bool check[3];
					check[0]=func(a,b,mp['t'],mp[vec[flg[i]][0]]);
					check[1]=func(a,b,mp['h'],mp[vec[flg[i]][1]]);
					check[2]=func(a,b,mp['a'],mp[vec[flg[i]][2]]) || func(a,b,mp['i'],mp[vec[flg[i]][2]]);
					if(check[0] && check[1] && check[2]){
						alpha=a;
						beta=b;
						break;
					}
				}
				if(alpha!=-1 || beta!=-1)break;
			}
			if(alpha!=-1 || beta!=-1)break;
		}
		string ans="";
		int alt;
		rep(i,vec.size()){
			rep(j,vec[i].size()){
				alt=mp[vec[i][j]];
				rep(k,alpha){
					alt=func(alpha,beta,alt);
				}
				ans+=rever[alt];
			}
			if(i!=vec.size()-1)ans+=" ";
		}
		cout<<ans<<endl;
	}
	return 0;
}