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>
using namespace std;
int main(void){
  int n,y;
  string str,ans;
  string s="abcdefghijklmnopqrstuvwxyz";
  cin >> n;
  getline(cin,str);
  for(int i=0;i<n;i++){
    getline(cin,str);
    for(int a=0;a<=100;a++){
      for(int b=0;b<=100;b++){
	ans.clear();
	for(int i=0;i<str.size();i++){
	  if(str[i]==' '){
	    ans+=' ';
	    continue;
	  }
	  for(int j=0;;j++){
	    if(str[i]==s[j]){
	      y=j;
	      break;
	    }
	  }
	  ans+=s[((a*y)+b)%26];
	}
	if(ans.find("that")==-1 && ans.find("this")==-1) continue;
	cout << ans << endl;
	goto lbl;
      }
    }
  lbl:;
  }
}

C++: #include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

string change(string s,int a,int b){
	string ret(s);
	rep(i,0,ret.size()){
		int y=ret[i]-'a';
		if(y>=0 && y<26){
			y=(a*y+b)%26;
			ret[i]='a'+y;
		}
	}
	return ret;
}

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

int main(){
	int n;
	//cin>>n;
	string tt;
	getline(cin,tt);
	n = atoi(tt.c_str());
	//cout<<n<<" "<<tt<<endl;
	//cin.ignore();
	string str[2]={"that","this"};
	rep(i,0,n){
		string s;
		bool f=0;
		getline(cin,s);
		//o(s);
		rep(a,0,26){
			if(gcd(a,26)!=1) continue;
			rep(b,0,26){
				string t;
				t=change(s,a,b);
				//o(t);
				rep(j,0,2){
					if(t.find(str[j]) != string::npos){
						o(t); f=1; break;
					}
				}
				if(f) break;
			}
			if(f) break;
		}

	}
}

C++: #include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
char c[257];
char d[257];
bool use[26];
int gcd(int a,int b){
	while(a){
		b%=a;
		int val=b;
		b=a;
		a=val;
	}
	return b;
}
int main(){
	int a;
	scanf("%d ",&a);
	while(a--){
		cin.getline(c,257);
		int t=strlen(c);
		for(int i=1;i<26;i++){
			for(int j=1;j<26;j++){
				bool ok=false;
//				if(gcd(i,26)>1)goto dame;
				for(int k=0;k<26;k++)use[k]=false;
				for(int k=0;k<26;k++){
					if(use[(i*k+j)%26])goto dame;
					else use[(i*k+j)%26]=true;
				}
				for(int k=0;k<t;k++){
					if(c[k]<='z'&&c[k]>='a'){
						d[k]=(i*(c[k]-'a')+j)%26+'a';
					}else{
						d[k]=c[k];
					}
				}
				d[t]=NULL;
				for(int k=0;k<t-3;k++){
					if(d[k]=='t'&&d[k+1]=='h'){
						if(d[k+2]=='a'&&d[k+3]=='t')ok=true;
						if(d[k+2]=='i'&&d[k+3]=='s')ok=true;
					}
				}
				if(ok){
					printf("%s\n",d);
					goto owari;
				}
				dame:;
			}
		}
		owari:;
	}
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int i,n;
	scanf("%d\n",&n);
	for(i=0;i<n;i++){
		string str;
		getline(cin,str);
//cout<<str<<endl;
		int a,b;
		for(a=1;a<26;a+=2){
			if(a==13)continue;
			for(b=0;b<26;b++){
				string st="";
				int j;
				for(j=0;j<str.size();j++){
					if('a'<=str[j]&&str[j]<='z'){
						st+=((str[j]-'a')*a+b)%26+'a';
					}else{
						st+=str[j];
					}
				}
//if(st[0]=='i')cout<<st<<endl;
				string::size_type index1=st.find("that");
				string::size_type index2=st.find("this");
				if(index1!=string::npos||index2!=string::npos){
					cout<<st<<endl;
					goto end;
				}
			}
		}
		end:;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(i=0;i<n;++i)
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define mp make_pair
#define pb push_back
#define fi first
#define sc second

int gcd(int p, int q){
  if(p<q) swap(p,q);
  while(q!=0){
    int tmp=p%q;
    p=q;
    q=tmp;
  }
  return p;
}

int main(int argc, char const *argv[]) {
  int i,j,k;

  string a="abcdefghijklmnopqrstuvwxyz";

  int n;
  scanf("%d\n",&n);
  for(int times=0; times<n; ++times){
    string s;
    getline(cin,s);
    //cout << s << endl;

    string ans;
    bool end=false;

    for(i=1; i<=25; ++i){//??¢???????????????
      if(gcd(26,i)!=1) continue;

      rep(j,26){
        //????????£?????§????¨?
        set<int> ch;
        rep(k,a.size()) ch.insert((i*k+j)%26);
        //??????
        if(ch.size()!=a.size()) continue;

        //printf("(%d,%d)\n",i,j);

        //?????????
        ans="";
        int p=0;
        rep(k,s.size()){
          if('a'<=s[k] && s[k]<='z'){
            ans+='a'+(i*(s[k]-'a')+j)%26;
          }
          else{
            ans+=s[k];
            string tmp=ans.substr(p,k-p);
            //cout << tmp << endl;

            if(tmp=="this"||tmp =="that")
              end=true;

            p=k+1;
          }
        }

        string tmp=ans.substr(p,k-p);
        //cout << tmp << endl;

        if(tmp=="this"||tmp =="that")
          end=true;


        if(end) break;
      }
      if(end) break;
    }

    std::cout << ans << std::endl;
  }
  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
	int n;
	int beta;
	string s;
	cin >> n;
	cin.ignore();
	for(int i=0;i<n;++i){
		beta=0;
		getline(cin , s);
		string org(256,'@');
		while(org.find("this" ,0)==string::npos && org.find("that" , 0)==string::npos){
				for(int alpha=0;alpha<500;++alpha){
						if(alpha){
							if(alpha%26==0|| 26%alpha==0) continue;
						}
						for(int k=0;k<26;++k){ 
							if((int)(s[0]-'a')==(int)((alpha*k+beta) % 26)){
								for(int l=0;l<s.size();++l){
									for(int m=0;m<26;++m){
										if(s[l]==' ') {org[l]=' ';  continue;}
										if((s[l]-'a')==((alpha*m+beta)%26)){
											org[l]=m+'a';
											break;
										}
									}
								}
							}
						}
				}
			beta++;
		}
		int index=org.find_first_of('@');
		org.erase(index);
		cout << org << endl;
	}
	return 0; 
}