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>
using namespace std;

#define rep(a, b, i) for(int i = a; i < b; i++)

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

int main() {
	int n, a, b, c;
	cin >> n;
	cin.ignore();

	string str, res = "";
	for (; n > 0; n--) {
		getline(cin, str);

		rep(1, 26, a) {
			if (a == 2 || a == 13) continue;
			rep(1, 26, b) {
				res = str;
				c = 0;
				rep(0, str.size(), c) {
					if (res[c] == ' ') continue;

					res[c] = ch(a, b, res[c]);
				}
				if (res.find("this") != -1 || res.find("that") != -1) {
					cout << res << endl;
					a = 114514;
					b = 114514;
				}
			}
		}
	}
	return 0;
}

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

using namespace std;

void solve()
{
	int N;
	scanf("%d\n", &N);
	while(N--)
	{
		string s;
		getline(cin, s);
		string sbuf = s;
		sbuf += ' ';
		int n = sbuf.size();
		int start = 0;
		int end = 0;
		vector<string> Vec;
		string temp;
		for(int i = 0; i < n; ++i)
		{
			if(sbuf[i] == ' ')
			{
				if(end - start == 4)
				{
					Vec.push_back(temp);
				}
				start = end = i + 1;
				temp.clear();
				continue;
			}
			temp += sbuf[i];
			++end;
		}
		int a = 0;
		int b = 0;
		for(int i = 0; i < Vec.size(); ++i)
		{
			for(int j = 0; j < 4; ++j)
			{
				Vec[i][j] %= 26;
			}
		}
		for(int i = 0; i < 26; ++i)
		{
			for(int j = 0; j < 27; ++j)
			{
				for(int k = 0; k < Vec.size(); ++k)
				{
					string check = "asdf";
					for(int l = 0; l < 4; ++l)
					{
						check[l] = (i * Vec[k][l] + j) % 26 + 'a';
					}
					if(check == "this" || check == "that")
					{
						a = i;
						b = j;
						goto END;
					}
				}
			}
		}
END:
		n = s.size();
		for(int i = 0; i < n; ++i)
		{
			if(s[i] == ' ')
			{
				cout << s[i];
				continue;
			}
			s[i] = (a * (s[i] % 26) + b) % 26 + 'a';
			cout << s[i];
		}
		cout << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
	
int F(int alpha,int beta,int ch){
	return (alpha*ch+beta)%26;
}
int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}
int main(){
	int n;
	string in,s,ans;
	cin>>n;
	getline(cin,in);
	while(n--){
		getline(cin,in);
		for(int i=1;i<26;i++){
			if(gcd(26,i)!=1)continue;
			for(int j=0;j<26;j++){
				for(int k=0;k<26;k++){
					table[F(i,j,k)] = k;
				}
				s.resize(in.size());
				for(int k=0;k<in.size();k++){
					if(in[k]==' ')s[k]=' ';
					else s[k] = table[in[k]-'a']+'a';
				}
				if(s.find("that",0)!=string::npos
					|| s.find("this",0)!=string::npos){
					cout<<s;
					goto BREAK;
				}
			}
		}
		BREAK:;
	}
	return 0;
}

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 < 300; i++){
      for(int j = 0; j < 300; 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 <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;

int n;
vector<string> s;
vector<string> st;
string t;
vector<int> a;
vector<int> b;
int al,be;
int alpa=-1,beta=-1;

int afin(char s,int u,int t);

int gcd(int x,int y){
	if(y==0) return x;
	return gcd(y,x%y);
}
void atis(string st,int al,int be){
	if(afin(st[2],al,be)==0&&afin(st[3],al,be)==19){
		alpa=al;
		beta=be;
		
	}
	if(afin(st[2],al,be)==8&&afin(st[3],al,be)==18){
		alpa=al;
		beta=be;
	}
}

bool th(string st){
	int al,be;
	rep(i,a.size()){
		rep(j,b.size()){
			if(afin(st[0],a[i],b[j])==19&&afin(st[1],a[i],b[j])==7){
				al=a[i];
				be=b[j];
				atis(st,al,be);
				//cout<<al<<" "<<be<<endl;
			}
		}
	}
}
//abcdefghijklmnopqrstuvwxyz
//012345678901234567890123456
			


int afin(char s,int u,int t){
	int c=s-'a';
	//cout<<s<<" "<<c<<endl;
	return (u*c+t)%26;
}

int main(){
	cin>>n;
	//string thth="thth";
	//printf("%d %d\n",thth[0],thth[1]);
	rep(i,100){
		if(gcd(i+1,26)==1){
			a.push_back(i+1);
			//cout<<i+1<<endl;
		}
	}
	rep(i,26) b.push_back(i);
	rep(k,n){
		s.clear();
		st.clear();
		
		
		int i=0;
		char tmp[300]={0};
		string tm;
		string tt;
		char tmtm;
		gets(tmp);
		//cout<<1<<" "<<tmp<<endl;
		gets(tmp);
		//cout<<2<<" "<<tmp<<endl;
		//cout<<tmp<<endl;
		rep(i,300){
			if(tmp[i]=='\n'){
				s.push_back(tm);
				//cout<<tm<<endl;
				break;
			}
			else if(tmp[i]==' '){
				s.push_back(tm);
				//cout<<tm<<endl;
				tm.clear();
			}
			else{
				tt=tmp[i];
				tm+=tt;
			}
		}
		
		//gets(tmp);
		//cout<<3<<" "<<tmp<<endl;
		
		//cout<<tmp;
		
		rep(i,s.size()){
			if(s[i].size()==4){
				st.push_back(s[i]);
				//cout<<s[i]<<endl;
			}
		}
		rep(i,st.size()){
			th(st[i]);
			//if(alpa>0) cout<<"alpa="<<alpa<<" beta="<<beta<<endl;
		}
		
		rep(i,s.size()){
			rep(j,s[i].size()){
				printf("%c",afin(s[i][j],alpa,beta)+'a');
			}
			
			if(i!=s.size()-1)	cout<<" ";
			else cout<<endl;
		}
		s.clear();
		//cout<<"hoge"<<endl;
	}
	return 0;
}