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 <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;
                    return 0;
                }
            }
        }
    }
    
    return 0;
}

C++: #include <stdio.h>
#include <string.h>

int al[] = { 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23 };
int alen = 11;

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

int affine(int a, int b, char *d, char *s, int len){
	for(int i=0;i<len; ++i){
		if(s[i] == ' '){
			d[i] = ' ';
		}else{
			d[i] = affine(a, b, s[i]) + 'a';
		}
	}
	d[len] = '\0';
	return 0;
}

bool is_true(char *x, int *a, int *b){
	char tmp[5];
	if(x[0] == x[3]){
		*b = x[2] - 'a';
		for(int i=0; i<alen; ++i){
			if(x[0] - 'a' == affine(al[i], *b, 't')){
				*a = al[i];
				affine(*a, *b, tmp, "that", 4);
				if(strcmp(tmp, x) == 0){
					return true;
				}else{
					return false;
				}
			}
		}
	}else{
		for(int i=0; i<alen; ++i){
			*b = ((x[0]-'a') - ('t'-'a') * al[i]) % 26;
			*b += *b >= 0 ? 0 : 26;
			affine(al[i], *b, tmp, "this", 4);
			if(strcmp(tmp, x) == 0){
				return true;
			}
		}
	}
	return false;
}

void raffine(char *dest, const char *source, int a, int b, int len){
	int table[26];
	for(int i=0; i<26; ++i){
		table[affine(a, b, i+'a')] = i;
	}
	for(int i=0; i<len; ++i){
		if(source[i] == ' ') { 
			dest[i] = ' ';
		}else{
			dest[i] = table[source[i]-'a'] + 'a';
		}
	}
	dest[len] = '\0';
}

int main(void){
	int n;
	char in[257];
	char cin[257];
	char *tmp;
	int len;
	int a=0, b=0;
	bool o = false;

	scanf("%d", &n);
	scanf("%c", in);
	for(int i=0; i<n; ++i){
		fgets(in, 256, stdin);
		len = strlen(in);
		in[--len] = '\0';
		strcpy(cin, in);

		tmp = strtok(cin, " ");
		if(strlen(tmp) == 4){
			if(is_true(tmp, &a, &b)){
				raffine(cin, in, a, b, len);
			}
		}else{
			while((tmp = strtok(NULL, " ")) != NULL){
				if(strlen(tmp) == 4 && is_true(tmp, &a, &b)){
					raffine(cin, in, a, b, len);
					break;
				}
			}
		}
		puts(cin);
	}
	return 0;
}

C++: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Main {
	public static void main(String[] args) throws IOException {
		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 += " " ;
						}
					}
					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 "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"
vector<string> split(const string &str, char delim) {
	vector<string> res;
	size_t current = 0, found;
	while ((found = str.find_first_of(delim, current)) != string::npos) {
		res.push_back(string(str, current, found - current));
		current = found + 1;
	}
	res.push_back(string(str, current, str.size() - current));
	return res;
}
long long int gcd(long long int l, long long int r) {
	assert(l > 0 && r > 0);
	if (l > r)return gcd(r, l);
	else {
		const long long int num = r%l;
		if (num) {
			return gcd(l, num);
		}
		else {
			return l;
		}
	}
}
vector<int>tha{ 19,7,0,19 };
vector<int>thi{ 19,7,8,18 };

int main() {
	int N; cin >> N;
	string st;
	getline(cin, st);
	while (N--) {
		getline(cin, st);
		vector<string>sts(split(st, ' '));
		vector<vector<int>>numss(sts.size());
		for (int i = 0; i < sts.size(); ++i) {
			for (auto c : sts[i]) {
				numss[i].emplace_back(c - 'a');
			}
		}

		vector<vector<int>>finans;
		for (int a = 1; a < 26; ++a) {
			if (gcd(a, 26) != 1)continue;
			for (int b = 0; b < 26; ++b) {
				bool ok = false;
				vector<vector<int>>anss(numss);
				for (auto& nums : anss) {
					for (auto&num : nums) {
						num = (a*num + b) % 26;
					}
					if (nums == tha || nums == thi) {
						ok = true;
					}
				}
				if (ok)finans = anss;
			}
		}
		//finans.emplace_back(tha);
		for (int i = 0; i < finans.size(); ++i) {
			for (int j = 0; j < finans[i].size(); ++j) {
				cout << char(finans[i][j] + 'a');
			}
			if (i == finans.size() - 1)cout << endl;
			else cout << " ";
		}
	}
	return 0;
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <map>

using namespace std;

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

typedef vector<int> vi;

int main()
{
	int n;
	scanf("%d%*c", &n);
	rep(i, n){
		char str[258];
		fgets(str, 258, stdin);

		set<string> words;
		stringstream stin(str);
		string tmp;
		while(stin >> tmp){
			if(tmp.size() == 4)
				words.insert(tmp);
		}

		int alpha=0, beta=0;
		bool keep = true;
		for(int i=1; keep; ++i){
			if(i%2==0 || i%13==0)
				continue;
			rep(j, 26){
				char samples[][5] = {"that", "this"};
				rep(k, 2){
					rep(l, 4) samples[k][l] = ((samples[k][l]-'a')*i+j)%26+'a';
					if(words.count(string(samples[k]))){
						alpha = i;
						beta = j;
						j=100;
						keep = false;
						break;
					}
				}
			}
		}

		map<char, char> conv;
		rep(i, 26)
			conv.insert(make_pair((i*alpha+beta)%26+'a', i+'a'));
		rep(i, strlen(str))
			putchar(isalpha(str[i]) ? conv[str[i]] : str[i]);
	}

	return 0;
}