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 <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;
						}
					}
				}
			}
		}
		getline(cin, str);
	}
	
	return 0;
}

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

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

string affine(string x){
	string tmp=x;
	for(int i=0; i<12; i++){
		int A=0;
		while(a[i]*A%26!=1)A++;
		for(int b=0; b<26; b++){
			if(tmp.find("this")==-1&&tmp.find("that")==-1){
					for(int s=0; s<x.size(); s++){
						if(isalpha(x[s]))tmp[s]=((A*(x[s]-'a')+26-b)%26)+'a';
					}
			}else return tmp;
		}
	}
	return tmp;
}

int main(){
	int n;
	string str;
	cin>>n;
	cin.ignore();
	while(n--){
		getline(cin, str);
		cout<<affine(str)<<endl;	
	}
	return 0;
}

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, 27, a) {
			if (a == 2 || a == 13) continue;
			rep(1, 27, 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 <cstring>
using namespace std;

int main(void) {
  string str1, str2;
  bool check;
  int n;
  cin >> n;
  getline(cin, str1);
  
  while(n--) {
    check = false;
    getline(cin, str1);
    
    for(int i = 1; i < 26; ++i) {
      if(check) {
        break;
      }
      if(i % 2 == 0 || i % 13 == 0) {
        continue;
      }
      for(int j = 0; j < 26; ++j) {
        str2 = str1;
        for(int k = 0; k < str1.size(); ++k) {
          if(str1[k] == ' ') {
            continue;
          }
          str2[k] = (((str1[k] - 'a') * i + j) % 26) + 'a';
        }
        if(str2.find("that") != -1 || str2.find("this") != -1) {
          check = true;
          cout << str2 << endl;
          break;
        }
      }
    }
  }
}

C++: #include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#define rep_to(a,i,n) for(i=a;i<n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define rep_r(i,n) for(i=n-1;i>=0;i--)
#define debug_i(x) printf("x:%d\n",x)
#define debug_s(str) printf("str:%s\n",str)
#define debug_c(c) printf("c:%c\n",c) 

int main()
{
	int i,j,k,l,z;
	int n=0;
	char str[257][257]={};
	char str2[257][257]={};
	char *p;
	int ans,count=1;
	int flag=0;
	scanf("%d\n",&n);

	rep(z,n)
	{
		fgets(str[0],sizeof(str[0]),stdin);
		str[0][strlen(str[0])-1]='\0';
		p=strtok(str[0]," ");
		strncpy(str[0],p,strlen(p));
		while(p!=NULL)
		{
			p=strtok(NULL," ");
			if(p!=NULL)
			{
				strncpy(str[count],p,strlen(p));
				count++;
			}
		}
		while(1)
		{
			rep_to(1,j,26)
			{
				rep(k,count)
				{
					rep(l,strlen(str[k]))
					{
						str2[k][l]=(i*(str[k][l]-97)+j)%26+97;
					}
				}
				rep(k,count)
				{
					if(strstr(str2[k],"that")!=NULL)flag=1;
					else if(strstr(str2[k],"this")!=NULL)flag=1;
				}
				if(flag==1)break;
			}
			if(flag==1)break;
			i++;
		}
		rep(i,count)
		{
			if(count-1!=i)printf("%s ",str2[i]);
			else printf("%s",str2[i]);
		}
		printf("\n");
		flag=0;
		count=1;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,i,j,k;string s,t;cin>>n;
	while(n--){getline(cin,s);t=s;
		for(i=99;i;i--)for(j=0;j<26;j++){
			for(k=0;k<s.size();k++)if(t[k]-32)t[k]=97+(i*s[k]+j)%26;
			if(t.find("this")+1||t.find("that")+1)goto p;
		}p:cout<<t<<endl;
	}return 0;
}

C++: #include <iostream>
#include <map>
#include <algorithm>
#include <cstdio>
#include <string>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;


int main(void){

int N,w;
string inl,wks,ans;
	
	getline(cin,wks);
	N = atoi(wks.c_str());

	rep(i,N){
		getline(cin,wks);
		rep(j,100) rep(k,26){
			inl = wks;
            for(int m=0; m < inl.size(); m++){
                if(inl[m] >= 'a' && inl[m] <= 'z')
            		inl[m]=( j * (inl[m]-'a') +k) %26 + 'a';
            }
//			if(j<2) cout << j <<"-" << k << ": " << inl << endl;
			if(inl.find("this") != string::npos 
            	|| inl.find("that") != string::npos ){
				ans = inl;
            	break;
            	
            }
		}
		cout << ans << endl;
	}	
	
	return 0;
	
	
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cctype>
#include<cstdlib>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
    int n;
    cin>>n;
    string str;
    getline(cin,str);
    while(n--){
        getline(cin,str);
        bool f=false;
        for(int a=1;!f;a++){
            if(a%2==0||a%13==0)continue;
            for(int b=0;!f&&b<26;b++){
                char m[26];
                for(int i=0;i<26;i++)m[(i*a+b)%26]=i+'a';
                string t=str;
                for(int i=0;i<t.size();i++){
                    if(islower(t[i]))t[i]=m[t[i]-'a'];
                }
                bool f_this=(t.find("this")!=string::npos);
                bool f_that=(t.find("that")!=string::npos);
                if(f_this||f_that){
                    str=t;
                    f=true;
                }
            }
        }
        cout<<str<<endl;
    }
}