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<string>
#include<algorithm>
using namespace std;
	
int F(int alpha,int beta,int ch){
	return (alpha*ch+beta)%26;
}
int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}
int main(){
	int n;
	string in,s,ans;
	cin>>n;
	getline(cin,in);
	while(n--){
		getline(cin,in);
		for(int i=1;i<26;i++){
			if(gcd(26,i)!=1)continue;
			for(int j=0;j<26;j++){
				int table[26];
				for(int k=0;k<26;k++){
					table[F(i,j,k)] = k;
				}
				s.resize(in.size());
				for(int k=0;k<in.size();k++){
					if(in[k]==' ')s[k]=' ';
					else s[k] = table[in[k]-'a']+'a';
				}
				if(s.find("that",0)!=string::npos
					|| s.find("this",0)!=string::npos){
					cout<<s;
					goto BREAK;
				}
			}
		}
		BREAK:;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
  int a[]={1,3,5,7,9,11,15,17,19,21,23,25};
  int n;
  cin >>n;
  cin.ignore();
  while(n--){
    string s,t;
    getline(cin,s);
    t = s;
    for(int i=0; i<12; i++){
      for(int j=0; j<26; j++){
	for(int k=0; k<s.size(); k++){
	  if(s[k]>='a' && s[k]<='z') t[k] = ((s[k]-'a')*a[i]+j)%26+'a';
	  else t[k] = s[k];
	}
	string::size_type pos_this = t.find("this");
	string::size_type pos_that = t.find("that");
	if(pos_this!=string::npos) cout <<t<<endl;
	else if(pos_that!=string::npos) cout <<t<<endl;
      }
    }
  }
  return 0;
}

C++: #include<iostream>
#include<cstring>
#include<set>
#include<map>
#define MAX 26
#include<algorithm>
#include<string>
using namespace std;
bool check(string s){
	for(int i=0;i<s.size()-3;i++){
		if((s.substr(i,4)=="that"||s.substr(i,4)=="this")&&(i==0||s[i-1]==' ')&&(i+4>=s.size()||s[i+4]==' '))
			return true;
	}
	return false;
}
int main(){
	int n;
	cin>>n;
	while(n>0){
		char S[1000];
		n--;
		string s="";
		fgets(S,1000,stdin);
		for(int i=0;i<strlen(S)-1;i++){
			s+=S[i];
		}
		for(int i=0;i<MAX;i++){
			for(int j=0;j<MAX;j++){
				if(__gcd(i,j)!=1){
					continue;
				}
				map<char,char> mp;
				set<int> st;
				for(int k=0;k<MAX;k++){
					int x;
					x=(i*k+j)%26;
					st.insert(x);
					mp[x+'a']=k+'a';
				}
				if(st.size()!=26)
					continue;
				string t=s;
				for(int k=0;k<s.size();k++){
					if(s[k]==' '){
						continue;
					}
					t[k]=mp[t[k]];
				}
				if(check(t)){
					cout<<t<<endl;
					goto end;
				}
				mp.clear();
				st.clear();
			}
		}
		end:;
	}
	return 0;
}

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]={};
	char str1[257][257]={};
	char str2[257][257]={};
	char *p;
	int ans,count=1;
	int flag=0;
	int len=0;
	scanf("%d\n",&n);

	rep(z,n)
	{
		fgets(str,sizeof(str),stdin);
		str[strlen(str)-1]='\0';
		i=0;
		j=0;
		k=0;
		rep(i,strlen(str))
		{
			if(str[i]==' ')
			{
				j++;
				k=0;
				i++;
				count++;
			}
			str1[j][k]=str[i];
			k++;
		}
		while(1)
		{
			rep_to(1,j,26)
			{
				rep(k,count)
				{
					rep(l,strlen(str1[k]))
					{
						str2[k][l]=(i*(str1[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)
		{
			rep(j,strlen(str2[i]))
			{
				if(len>=strlen(str))break;
				else 
				{
					printf("%c",str2[i][j]);
					len++;
				}
			}
			if(len>=strlen(str))break;
			else printf(" ");
			len++;
		}
		printf("\n");
		flag=0;
		rep(i,strlen(str))str[i]='\0';
		rep(i,count)rep(j,strlen(str2[i]))str2[i][j]='\0';
		rep(i,count)rep(j,strlen(str1[i]))str1[i][j]='\0';
		count=1;
		i=0;
		len=0;
	}
	return 0;
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int a, b;

void check(int A[], char inp[]){
    int k;
    rep(i, 100){
        rep(j, 100){
            if((i * A[0] + j) % 26 == inp[0] - 'a'){
                for(k = 1; k < 4; k++){
                    if((i * A[k] + j) % 26 != inp[k] - 'a') break;
                }
            }
            if(k == 4){
                a = i;
                b = j;
                return;
            }
        }
    }
}

int main(){
    char str[256][256];
    char inp[256];
    int len,n,l;
    int This[4] = {19, 7, 8, 18}, That[4] = {19, 7, 0, 19};
    while(cin >> n){
        rep(i,n){
            len = 0;
            a = b = -1;
            while(cin >> inp){
                strcpy(str[len], inp);
                len++;
                if(strlen(inp) == 4){
                    check(This, inp);
                    if(a == -1)
                        check(That, inp);
                }
            }
            rep(j,len){
                rep(k, strlen(str[j])){
                    rep(l,26){
                        if((a * l + b) % 26 == str[j][k] - 'a'){
                            printf("%c",'a' + l);
                        }
                    }
                }
                cout << ' ';
            }
            cout << endl;
        }
    }
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,i,j,k;string s,t;cin>>n;getline(cin,s);
	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;
}