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<map>

using namespace std;

int a,b;
map<char, char> M;

char Affine(char c){
  return ((a*(c-'a') + b) % 26) + 'a';
}


void make(){
  M.clear();
  for(char c = 'a'; c <= 'z'; c++)
    M[Affine(c)] = c;
}


bool check(string in){
  string now = "";
  for(int i = 0; i < in.length(); i++){
    if(in[i] == ' '){
      //   cout << "now = " << now << endl;
      if(now == "this" || now == "that") return true;
      now = "";
    }
    else now += in[i];
  }
  return false;
}

string solve(string s){
 
  for(int i = 0; i < s.length(); i++)
    if(s[i] != ' ') s[i] = M[s[i]];

  if(check(s)) return s;
  return "-1";

}

void print(){
  for(char c = 'a'; c <= 'z'; c++)
    cout << M[c] << " ";

  cout << endl;

}

int GCD(int x,int y){
  if(y==0) return x;
  return GCD(y,x%y);
}
int main(){
  
  // print();
  // return 0;
  int n;
  cin >> n;
  cin.ignore();
  while(n--){
    string s;
    bool flg = false;
    getline(cin,s);
    for(int i = 0; i < 200; i++){
      for(int j = 0; j < 200; j++){
	a = i;
	b = j;
	if(GCD(a,26) != 1) continue;
	
	make();
	string ans;
	
	if((ans = solve(s)) != "-1"){
	  flg = true;
	  cout << ans << endl;
	  break;
	}
      }
      if(flg) break;
    }
    
  }
  return 0;
}

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

char getDigit(int alpha, int beta, char y)
{
    int buff;
    y = y - 'a';
    buff = (alpha * y + beta) % 26;
    buff += 'a';
    return (char) buff;
}

int main()
{
    int n;
    string context;

    cin >> n;

    for(int i =0; i < n; i++)
    {
        cin >> context;
        while(1)
        {
            for(int alpha = 0; alpha <= 50; alpha++)
            for(int beta = 0; beta <= 26; beta++)
            {
                for(int j = 0; j < context.size(); j++) context[j] = getDigit(alpha, beta, context[j]);
                if(string::npos != context.find("that", 0)) break;
                if(string::npos != context.find("this", 0)) break;
            }
        }
        cout << context << endl;
    }


}

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

string conv(map<char,char> &table,string a){
	for(int i=0;i<a.length();i++){
		if(a[i] != ' ')a[i] = table[a[i]];
	}
	return a;
}

int main(){
	int n;
	string s;
	scanf("%d\n",&n);
	while(n--){
		getline(cin,s);
		for(int a=0;a<26;a++){
			for(int b=0;b<26;b++){
				/*  */
				map<char,char> table;
				for(int i=0;i<26;i++){
					 table['a'+i] = 'a' + (a * i + b) % 26;
				}
				if(table.size()==26){
					string ret = conv(table,s);
					if(~ret.find("this")||~ret.find("that"))cout << ret << endl;
				}
			}
		}
	}
}

C++: #include <iostream>
#include <string>
using namespace std;
int main()
{
	int n ; cin >> n;
	string str; getline(cin,str); //ignore
	while(n--)
	{
		getline(cin,str);
		int alpha[26];
		int a=0,b=0; bool flag=false;
		for( ;a<26;a++)
		{
			if(a%2==0 || a%13==0) continue;
			for(b=0;b<26;b++)
			{
				for(int r=0;r<26;r++) alpha[r]=(a*r+b)%26;
				bool table[26]={0}; int k=0;
				for( ;k<26;k++)
					if(table[alpha[k]]) break;
				if(k<26) break;
				string THIS="", THAT="";
				THAT+=('a'+alpha['t'-'a']); THAT+=('a'+alpha['h'-'a']); THAT+=('a'+alpha[0]); THAT+=('a'+alpha['t'-'a']);
				THIS+=('a'+alpha['t'-'a']); THIS+=('a'+alpha['h'-'a']); THIS+=('a'+alpha['i'-'a']); THIS+=('a'+alpha['s'-'a']);
				for(int i=0;i<str.size();i++)
				{
					string ss=str.substr(i,4);
					if(ss==THAT || ss==THIS) {flag=true; break;}
				}
				if(flag) break;
			}
			if(flag) break;
		}
		string ans="";
		for(int i=0;i<str.size();i++)
		{
			char ch; ch=str[i];
			if(!islower(ch)) ans+=ch;
			else
			{
				for(int j=0;j<26;j++)
					if(alpha[j]==ch-'a') {ans+=('a'+j); break;}
			}
		}
		cout << ans << endl;
		//for(int i=0;i<26;i++) cout << alpha[i] << ' ' ; cout << endl;
	}
}

C++: #include <string>
#include <iostream>
#include <map>
#include <cstdio>
 
using namespace std;
 
int AffineCipher(int a, int b, const char c){
	return (a*(c-'a')+b)%26 + 'a';
}

int main(){
    string s, s2;
	string kw[] = {"this", "that"};
	string alpha = "abcdefghijklmnopqrstuvwxyz";
	char decode[256];

	int n;
	getline(cin, s);
	n = atoi(s.c_str());
	const int sc = 1000;

    while(n--){
		getline(cin, s);
		string ckw[2] = {kw[0], kw[1]};
		bool found = false;
		int p;

		for(int a = 1; a < sc && !found; a+=2){
			for(int b = 0; b < 26; b++){
				for(int i = 0; i < kw[0].size();i++){
					ckw[0][i] = AffineCipher(a, b, kw[0][i]);
					ckw[1][i] = AffineCipher(a, b, kw[1][i]);
				}
				if(s.find(ckw[0]) != -1 || s.find(ckw[1]) != -1){
//					cout << a << " " << b << endl;
					for(int i = 0; i < 26; i++){
						decode[AffineCipher(a, b, alpha[i])] = alpha[i];
					}
					for(int i = 0; i < s.size(); i++){
						if(isalpha(s[i])){
							s[i] = decode[s[i]];
						}
					}
					cout << s << endl;
					found = true;
					break;
				}
			}
		}
	}
  
    return 0;
}