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 <stdio.h>
#include <stack>

using namespace std;


//??¨??¬??????a,b????????????????????????????????¢??°
bool judge(int a, int b){
	int checkTable[26];
	for(int i=0;i<26;i++)checkTable[i] = 0;
	for(int i=0;i < 26;i++){
		if(checkTable[(a*i+b)%26] == 0){
			checkTable[(a*i+b)%26] = 1;
		}else{
			return false;
		}
	}
	return true;
}


int main(){
	int n,length,a,b;
	char buf[300],convert[26],s1,s2,s3,s4;
	bool FLG;

	scanf("%d",&n);
	getchar();
	for(int i=0;i<n;i++){
		fgets(buf,300,stdin);
		length = 0;
		FLG = false;
		//??????4?????????????????¢??????a,b?????????????????????
		for(int k=0;buf[k] != '\0';k++){
			if(buf[k] == ' '){
				if(length == 4){

					s1 = buf[k-4] - 97;
					s2 = buf[k-3] - 97;
					s3 = buf[k-2] - 97;
					s4 = buf[k-1] - 97;

					//this??§??¨??¬
					if(s1 > s4){
						a = s1 - s4;
					}else{
						a = (s1 + 26) -s4;
					}
					b = -1;
					for(int p=0;p<26;p++){
						if((19*a+p)%26==s1 && (7*a+p)%26 == s2 && (8*a+p)%26 == s3 && (18*a+p)%26 == s4){
							b = p;
							if(judge(a,b)){
								FLG = true;
								break;
							}
						}
					}
					if(FLG){
						break;
					}

					if(s1 == s4){
						//that??§??¨??¬
						a = -1;
						b = s3;
						for(int p=0;p<26;p++){
							if((19*p+b)%26==s1 && (7*p+b)%26==s2){
								a = p;
								if(judge(a,b)){
									FLG = true;
									break;
								}
							}
						}
						if(FLG){
							break;
						}
					}
				}
				length = 0;
			}else if(buf[k+1] == '\n' || buf[k+1] == '\0'){
				length++;
				if(length == 4){

					s1 = buf[k-3] - 97;
					s2 = buf[k-2] - 97;
					s3 = buf[k-1] - 97;
					s4 = buf[k] - 97;

					//this??§??¨??¬
					if(s1 > s4){
						a = s1 - s4;
					}else{
						a = (s1 + 26) -s4;
					}
					b = -1;
					for(int p=0;p<26;p++){
						if((19*a+p)%26==s1 && (7*a+p)%26 == s2 && (8*a+p)%26 == s3 && (18*a+p)%26 == s4){
							b = p;
							if(judge(a,b)){
								FLG = true;
								break;
							}
						}
					}
					if(FLG){
						break;
					}


					//that??§??¨??¬
					if(s1 == s4){
						a = -1;
						b = s3;
						for(int p=0;p<26;p++){
							if((19*p+b)%26==s1 && (19*p+b)%26 == s1 && (7*p+b)%26==s2){
								a = p;
								if(judge(a,b)){
									FLG = true;
									break;
								}
							}
						}
						if(FLG){
							break;
						}
					}
				}
				length = 0;
			}else{
				length++;
			}
		}

		//????????¨?????????
		for(int k = 0; k < 26;k++)convert[(a*k+b)%26] = k;

		for(int k=0;buf[k] != '\0';k++){
			if(buf[k]>=97 && buf[k] <= 122){
				buf[k] = convert[buf[k]-97]+97;
			}
		}
		printf("%s\n",buf);
	}

    return 0;
}

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

int main(){
	int gomi;
	cin >> gomi;
	cin.ignore();
	string str;
	while(getline(cin,str)){
		bool hata = false;
		int a = 0, b = 0;
		int p=-1,q;
		for(int i = 0; i < str.size()+1; i++){
			if(str[i] == ' ' || i == str.size()){
				q = i;
				if(q-p == 5){
					for(int j = 1; j < 26; j++){
						if(j%2==0 || j == 13){
							continue;
						}
						if((j*('t'-'a')-(str[i-4]-'a')-j*('h'-'a')+(str[i-3]-'a'))%26 == 0){
							if((j*('h'-'a')-(str[i-3]-'a')-j*('a'-'a')+(str[i-2]-'a'))%26 == 0 && (j*('a'-'a')-(str[i-2]-'a')-j*('t'-'a')+(str[i-1]-'a'))%26 == 0 ){
								a = j;
								b = ((str[i-4]-'a')-j*('t'-'a'))%26;
								if(b < 0){
									b += 26;
								}
								hata = true;
								break;
							}
							else if((j*('h'-'a')-(str[i-3]-'a')-j*('i'-'a')+(str[i-2]-'a'))%26 == 0 && (j*('i'-'a')-(str[i-2]-'a')-j*('s'-'a')+(str[i-1]-'a'))%26 == 0 ){
								a = j;
								b = ((str[i-4]-'a')-j*('t'-'a'))%26;
								if(b < 0){
									b += 26;
								}
								hata = true;
								break;
							}
						}
					}
				}
				p = q;
			}
			if(hata == true){
				break;
			}
		}
		for(int i = 0; i < str.size(); i++){
			if(str[i] != ' '){
				for(int j = 0; j < 26; j++){
					if(str[i]-'a' == (j*a+b)%26){
						str[i] = 'a'+j;
						break;
					}
				}
			}
		}
		cout << str << endl;
	}
}

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

using namespace std;

int a, b;
const int alpha[] = {1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25};

inline char affine(char ch)
{
    return (alpha[a] * ch + b) % 26 + 'a';
}

void solve()
{
    string str;

    getline(cin, str);
    str += ' ';
    string::size_type pos1, pos2;
    bool flag = false;

    for (pos2 = str.find(' '), pos1 = 0; pos2 != string::npos;
         pos1 = pos2 + 1, pos2 = str.find(' ', pos1)) {
        if (str.substr(pos1, pos2 - pos1).size() == 4) {
            string tmp = str.substr(pos1, pos2 - pos1);

            for (int ai = 0; ai < 12; ai++) {
                for (int bi = 1; bi < 26; bi++) {
                    string cmp = "";
                    a = ai;
                    b = bi;

                    for (int i = 0; i < tmp.size(); i++) 
                        cmp.push_back(affine(tmp[i]));
                    if (cmp == "this" || cmp == "that") {
                        flag = true;
                        break;
                    }
                    if (flag)
                        break;
                }
                if (flag)
                    break;
            }
        }
        if (flag)
            break;
    }

    for (int i = 0; i < str.size(); i++) {
        if (isalpha(str[i]))
            cout << affine(str[i]);
        else
            cout << str[i];
    }
    cout << endl;
}


int main()
{
    int n;
    
    cin >> n;
    cin.ignore();
    while (n--) {
        solve();
    }

    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);

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