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>
#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 i=0; i<n; i++){
    string s;
    getline(cin, s);

    for(int i=0; i<26; i++){
      for(int j=0; j<26; 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];
        }
        // cout << t << endl;
        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<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++){
      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 SIZE 300005
#define MOD 1000000007LL
#define INF INT_MAX / 3
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define FORALL(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef valarray<int> Array;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cout<<a[i];if(i==a.size()-1)cout<<endl;else cout<<" ";}}
int gcd(int a,int b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
int lcm(int a,int b){return a==0||b==0?0:a*b/gcd(a,b);}


void solve(string s)
{
  int a = 0, b = 0;
  for(int i = 0; i < s.size();)
  {
    int l = 0;
    bool f = false;
    while(i+l < s.size()&&s[i+l] != 0x20) l++;
    if(l != 4) i += l+1;
    else
    {
      string t = "";
      REP(j,4) t += s[i+j];
      FOR(v,1,25)
      {
        if(gcd(v,26)!=1) continue;
        FOR(w,0,25)
        {
          string tmp = t;
          REP(j,4) tmp[j] = 'a'+((v*(t[j]-'a')+w)%26);
          if(tmp == "this" || tmp == "that")
          {
            a = v; b = w; f = true;
            break;
          }
        }
        if(f) break;
      }
    }
    if(f) break;
    i += l+1;
  }
  REP(i,s.size()) if(s[i] != 0x20)s[i] = 'a'+((a*(s[i]-'a')+b)%26);
  cout << s << "\n";
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n; cin.ignore();
  REP(i,n)
  {
    string s;
    getline(cin,s);
    solve(s);
  }
  return 0;
}

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

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

int main()
{
	int n;
	scanf("%d ", &n);
	for (int c = 0; c < n; c++){
		string str;
		getline(cin, str);
		
		for (int a = 1; a <= 26; a++){
			if (gcd(a, 26) != 1) continue;
			for (int b = 0; b < 26; b++){
				string cpy(str);
				for (int i = 0; i < str.size(); i++){
					if (cpy[i] == ' ') continue;
					cpy[i] = ((cpy[i] - 'a') * a + b) % 26 + 'a';
				}
				for (int i = 0; i < (int)str.size() - 3; i++){
					string t(cpy, i, 4);
					if (t == "that" || t == "this"){
						cout << cpy << endl;
						goto BREAK;
					}
				}
			}
		}
		
		BREAK:;
	}
	
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  cin>>n;
  rep(i,n){
    string s;
    string ans;
    bool han=false;
    if(i==0)getline(cin,s);
    getline(cin,s);
    rep(a,27){
      rep(b,27){
	string tmp=s;
	rep(j,tmp.size())if(isalpha(tmp[j]))tmp[j]=(a*(tmp[j]-'a')+b)%26+'a';
	rep(j,tmp.size()-3){
	  if(tmp.substr(j,4)=="this"){ans=tmp;han=true;}
	  if(tmp.substr(j,4)=="that"){ans=tmp;han=true;}
	}
	if(han==true)break;
      }
      if(han==true)break;
    }
    cout<<ans<<endl;
  }


}

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, 28, a) {
			if (a == 2 || a == 13) continue;
			rep(1, 28, 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<map>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cmath>
using namespace std;
int inf = 1000000000;

int main(){

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

    bool f = true;
    for(int i=1; i<50&&f; i++){
      if( i % 2 == 0 || i % 13 == 0 ) continue;
      for(int j=1; j<50&&f; j++){
        string t = s;
        for(int k=0; k<s.size(); k++){
          if( 'a' <= t[k] && t[k] <= 'z' ) t[k]=(i*(t[k]-'a')+j)%26+'a';
        }
        if( t.find("that") != -1 || t.find("this") != -1 ){cout << t << endl; f = false; break;}
      }
    }

  }


  return 0;
}