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<30; i++){
      for(int j=0; j<30; 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++: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		Scanner cin = new Scanner(System.in);
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i = 2; i < 100; i++){
			if(gcm(26,i)==1){
				list.add(i);
			}
		}
		String NN =br.readLine(); 
		int N = Integer.parseInt(NN);
		while(N--!=0){
			String str = br.readLine();
			label:for(int i = 0; i < list.size(); i++){
				
				for(int j = 0; j < 26; j++){
					String nstr = "";
					for(int k = 0; k < str.length(); k++){
						if(Character.isLetter(str.charAt(k))){
							nstr += (char)(((list.get(i)*(str.charAt(k)-'a') + j)%26) + 'a');
						}
						else{
							nstr += " " ;
						}
						//nstr+=str.charAt(k);
					}
					if(nstr.contains("that") || nstr.contains("this")){
						System.out.println(nstr);
						break label;
					}
				}
			}
		}
	}
	static int gcm(int p, int q){
		if(p < q){
			int tmp=p;
			p=q;
			q=tmp;
		}
		if(q==0){
			return p;
		}
		else{
			return gcm(q, p%q);
		}
	}
}

C++: #include <string>
#include <iostream>
#include <cctype>
#include <algorithm>
#include <cstdlib>
using namespace std;
char f(int a, int b, int c) { return (a*c + b) % 26 + 'a'; }
int main()
{
	string p; getline(cin, p);
	int N = atoi(p.c_str());
	while (N--) {
		string s; getline(cin, s);
		for (int a=0; a<26; ++a) {
			if (__gcd(a, 26) != 1) continue;
			for (int b=0; b<26; ++b) {
				string t = s;
				bool ok = true;
				for (int i=0; i<s.size(); ++i) {
					if (isalpha(s[i])) {
						t[i] = f(a, b, s[i]-'a');
						if (!isalpha(t[i])) { ok = false; break; }
					}
					else t[i] = s[i];
				}
				if (ok && t.find("that") != string::npos || t.find("this") != string::npos) {
					cout << t << endl;
					goto BREAK;
				}
			}
		}
BREAK:;
	}
	return 0;
}

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

int main(){
	int n;
	string str;
	bool output;
	int code;
	int str1[4] = {19, 7, 8, 18};
	int str2[4] = {19, 7, 0, 19};
	
	cin >> n;
	
	getline(cin, str);
	for(int i = 0; i < n; i++){
		getline(cin, str);
		
		output = false;
		
		for(int a = 0; !output && a < 26; a++){
			for(int b = 0; !output && b < 26; b++){
				for(int p = 0; !output && p < str.size() - 4; p++){
					for(int c = 0; !output && c < 4; c++){
						code = (a * (str[p + c]-97) + b) % 26;
						if(code != str1[c]) break;
						else if(c + 1 == 4){
							output = true;
							for(int P = 0; P < str.size(); P++){
								if(str[P] != ' ') cout << (char)((a * (str[P]-97) + b) % 26 + 97);
								else cout << " ";
							}
							cout << endl;
						}
					}
					for(int c = 0; !output && c < 4; c++){
						code = (a * (str[p + c]-97) + b) % 26;
						if(code != str2[c]) break;
						else if(c + 1 == 4){
							output = true;
							for(int P = 0; P < str.size(); P++){
								if(str[P] != ' ') cout << (char)((a * (str[P]-97) + b) % 26 + 97);
								else cout << " ";
							}
							cout << endl;
						}
					}
				}
			}
		}
	}
	
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define MAX_N 5001
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<string, ll> PS;
typedef vector<ll> V;

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n;
string s, ans;

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

	if (b == 1)return true;

	return gcd(b, a%b);
}

int main(){
	cin >> n;
	cin.ignore();
	REP(i, n){
		getline(cin, s);
		bool f = 0;
		for (int j = 1; j < 26; j++){
			if (!gcd(26, j))continue;
			for (int k = 0; k < 26; k++){
				//cout << j << " " << k << endl;
				REP(l, s.size()){
					if (s[l]<'a' || s[l]>'z'){
						ans += s[l];
						continue;
					}
					ans += (j*(s[l] - 'a') + k) % 26 + 'a';
				}
				if (ans.find("this") != -1
					|| ans.find("that") != -1)f = 1;
				if (f)break;
				ans.clear();
			}
			if (f)break;
		}

		cout << ans << endl;
		ans.clear();
	}
}

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

int main() {
	int n;
	cin >> n;
	for (int i = 0;i < n;i++) {
		string s;
		getchar();
		getline(cin, s);
		int a = s.size();

		for (int j = 0;j < 26;j++) {
			for (int k = 0;k < 26;k++) {
				string sa = s;
				for (int l = 0;l < a;l++) {
					if (sa[l] >= 'a'&&sa[l] <= 'z') {
						int b = sa[l] - 97;
						b =( b*j + k)%26;
						b += 97;
						sa[l] = b;
					}
					size_t za = sa.find("that");
					size_t zb = sa.find("this");
					if (za != string::npos || zb != string::npos) {
						s = sa;
						goto finloop;
					}
				}
			}
		}
	finloop:
		cout << s << endl;
	}
	return 0;
}