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 <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n;
  cin >> n;
  cin.ignore();
  while(n--) {
    string s;
    getline(cin,s);
    int f = 0;
    for (int a=0;f==0;a++) {
      string buf(s);
      REP(b,26) {
        REP(i,s.length()) {
          if (s[i]!=' ') {
            buf[i] = ((s[i]-'a')*a+b)%26 + 'a';
          }
        }
        if (buf.find("that")!=-1||buf.find("this")!=-1) {
          cout << buf << endl;
          f = 1;
          break;
        }
      }
    }
  }
}

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

int main(){
    int n=10;
    cin>>n;
    string str;
    n++;
    while(n--){
        getline(cin,str);
        for(int i=3;i<99;i++){
            if(i%2==0||i%13==0)continue;
            for(int j=0;j<26;j++){
                vector<int>vec;
                for(int k=0;k<26;k++){
                    vec.push_back((i*k+j)%26);
                }
                sort(vec.begin(),vec.end());
                if(unique(vec.begin(), vec.end())!=vec.end())continue;
                string ss=str;
                for(int k=0;k<str.length();k++){
                    if(str[k]>='a'&&str[k]<='z')
                        ss[k]=((i*(str[k]-'a')+j)%26)+'a';
                    else ss[k]=str[k];
                }
                int len=ss.length();
                for(int k=0;k<len-3;k++){
                    if(ss.substr(k,4)=="this"||ss.substr(k,4)=="that"){
                        cout<<ss<<endl;
                        goto next;
                    }
                }
            }
        }
    next:;
    }
}

C++: #include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int t;
    cin >> t; cin.ignore();
    string s;
    while(t--){
        getline(cin, s);
        [&](){
            for (int i = 0; i < 26; ++i) {
                for (int j = 0; j < 26; ++j) {
                    string a = s;
                    for (auto &&k : a) {
                        if(isalpha(k)) k = ((k-'a')*i+j)%26+'a';
                    }
                    if(a.find("this") != string::npos || a.find("that") != string::npos){
                        cout << a << "\n";
                        return;
                    }
                }
            }
        }();
    }
    return 0;
}

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

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

int main() {
  string line;
  int Tc;
  cin >> Tc;
  cin.ignore();
  while(Tc--) {
    getline(cin, line);
    for(int a = 1; a < 26; ++a) {
      for(int b = 0; b < 26; ++b) {
	if(gcd(a, 26) != 1) continue;
	string t = line;
	for(int i = 0; i < t.size(); ++i) {
	  if(isalpha(t[i])) {
	    int r = t[i] - 'a';
	    t[i] = (a*r+b)%26+'a';
	  }
	}
	if(t.find("that") != string::npos ||
	   t.find("this") != string::npos) {
	  cout << t << endl;
	  a = b = (1<<28);
	  break;
	}
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

map<char, char> computeMap(int a, int b) {
	map<char, char> res;
	for (int x = 0; x < 26; x++) {
		int y = (a * x + b) % 26;
		res[y + 'a'] = x + 'a';
	}

	return res;
}

string decode(string str, map<char, char> m) {
	for (auto &c : str) {
		c = isalpha(c) ? m[c] : c;
	}
	return str;
}

string solve(string str) {
	for (int a = 0; a < 25; a++) {
		for (int b = 0; b < 25; b++) {
			if (__gcd(a, 26) != 1) continue;
			map<char, char> m = computeMap(a, b);
			string decoded = decode(str, m);
			if (decoded.find("that") != string::npos || 
				decoded.find("this") != string::npos) {
				return decoded;
			}
		}
	}
	return "hoge";
}

int main(void) {
	int N;
	cin >> N;
	cin.get();

	for (int i = 0; i < N; i++) {
		string str;
		getline(cin, str);
		cout << solve(str) << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<string>
#include<sstream>
int calc_alpha(const std::string&w, const char*str)
{
	auto distance = [](char from, char to)
	{
		int result = static_cast<int>(to - from);
		return result + (result < 0 ? 26 : 0);
	};
	int dis1[3], ratio[3];
	for (int j = 0; j < 3; j++)
	{
		dis1[j] = distance(w[j], w[j + 1]);
		int dis2 = distance(str[j], str[j + 1]);
		while (true)
		{
			if (dis1[j] % dis2 == 0)
			{
				ratio[j] = dis1[j] / dis2;
				break;
			}
			dis1[j] += 26;
		}
	}
	return ratio[0] == ratio[1] && ratio[1] == ratio[2] ? ratio[0] : -1;
}
int main()
{
	int n;
	std::cin >> n;
	std::cin.ignore();
	for (int i = 0; i < n; i++)
	{
		std::string str;
		std::getline(std::cin, str);
		std::stringstream ss(str);
		int alpha, beta;
		for (std::string w; ss >> w;)
		{
			if (w.length() == 4)
			{
				alpha = w[0] == w[3] ? calc_alpha(w, "that") : calc_alpha(w, "this");
				if (alpha != -1)
				{
					beta = static_cast<int>(w[0] - 'a' - ('t' - 'a') * alpha % 26);
					break;
				}
			}
		}
		char deciphered[26];
		for (char j = 'a'; j <= 'z'; j++)
		{
			char ciphered = ((j - 'a') * alpha + beta) % 26 + 'a';
			deciphered[ciphered - 'a'] = j;
		}
		for (auto j : str)
		{
			std::cout << (j == ' ' ? ' ' : deciphered[j - 'a']);
		}
		std::cout << std::endl;
	}
	return 0;
}