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>
#include <vector>

using namespace std;

const char table[] = "abcdefghijklmnopqrstuvwxyz";

void reFunc(char *pstr, int *a, int *b) {
	int i, len, index;

	len = strlen(pstr);
	for (i = 0; i < len; i++) {
		for (index = 0; index < 26; index++) {
			if (table[(*a*index + *b) % 26] == pstr[i]) {
				cout << table[index];
			}
		}
	}
}


int findFactor(char *pstr, int *pa, int *pb) {
	int i, j;

	for (i = 1; ; i++) {
		if (i == 26) {
			return 0;
		}
		if (i == 13 || 26 % i == 0) {
			if (i != 1) {
				continue;
			}
		}

		for (j = 0; ; j++) {
			if (table[(i * 19 + j) % 26] == pstr[0]) {     //t
				if (table[(i * 7 + j) % 26] != pstr[1]) {  //h
					break;
				}
				if (table[(i * 0 + j) % 26] != pstr[2] && table[(i * 8 + j) % 26] != pstr[2]) {  //a i
					break;
				}
				if (table[(i * 19 + j) % 26] != pstr[3] && table[(i * 18 + j) % 26] != pstr[3]) {  //t s
					break;
				}

				*pa = i;
				*pb = j;
				return 1;

			}
		}
	}
}

int main(void) {
	int n, i, size, a, b,j;
	char str[260];
	char *pstr;
	vector<char *> vstr;

	cin >> n;
	cin.ignore();
	for (i = 0; i < n; i++) {
		cin.getline(str, 260);
		//cout << "str:"<<str << endl;
		pstr = strtok(str, " ");
		while (pstr != NULL) {
			vstr.push_back(pstr);
			//cout << "substr:" << pstr << endl;
			pstr = strtok(NULL, " ");
		}

		size = vstr.size();
		for (j = 0; j < size; j++) {
			if (strlen(vstr[j]) == 4) {
				if (findFactor(vstr[j], &a, &b)) {
					break;
				}
			}
		}

		for (j = 0; j < size; j++) {
			reFunc(vstr[j], &a, &b);
			if (j != size - 1) {
				cout << " ";
			}
		}
		cout << endl;
		vstr.clear();
	}

	return 0;
}

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

int affine(int m, int a, int b){
  return (m * a + b) % 26;
}

int main(void){
  int n;
  string c, p;
  cin >> n; cin.ignore();
  
  while(n--){
    getline(cin, c); p = c;
    for(int a = 1; a < 100; a++){
      for(int b = 1; b < 26; b++){
        for(int i = 0; i < p.size(); i++){
          if(c[i] != ' ') p[i] = (char)(affine(c[i] - 'a', a, b) + 'a');
        }
        
        if(p.find("this") != string::npos || p.find("that") != string::npos){
          cout << p << endl;
          break;
        }
      }
    }
  }
  return 0;
}

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

vector<int> a;
vector<int> b;
int id=2;
int N;
int yukuri(int n,int m){
  if(n<m) swap(n,m);
  while(m>0){
    int tmp = n%m;
    n=m;
    m=tmp;
  }
  return n;
}

void add_ab(){
  ++id;
  while(yukuri(id,26)!=1) id++;
  for(int i=0;i<26;i++){
    a.push_back(id);
    b.push_back(i);
  }
}
int F(char y,int id){
  return ((int)(y-'a')*a[id]+b[id])%26;
}
string change(string s,int id){
  for(int i=0;i<(int)s.size()-1;i++){
    if(s[i]==' ') continue;
    s[i]=(char)F(s[i],id)+'a';
  }
  return s;
}

int main(){
  scanf("%d",&N);
  add_ab();

  getchar();
  for(int i=0;i<N;i++){
    char buf[258];
    fgets(buf,sizeof(buf),stdin);
    string s = buf;
    for(int i=0;i<(int)a.size();i++){
      s=change(s,i);
      if(0<=(int)s.find("that") || 0<=(int)s.find("this")){
	printf("%s",s.c_str());
	break;
      }
      //      printf("ng:: %s",s.c_str());
      s=buf;
      if(i==(int)a.size()-1){
	add_ab();
      }
    }
  }
}

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

using namespace std;

string table(int a, int b) {
    string str;
    for(int i = 'a'; i <= 'z'; ++i)
        str += ((i-'a')*a+b) % 26 + 'a';
    string rev;
    rev.resize(26);
    for(int i = 0; i < str.size(); ++i)
        rev[str[i]-'a'] = i+'a';
    return rev;
}

int main() {
    int N;
    cin >> N;
    cin.ignore();
    while(N--) {
        string str;
        getline(cin, str);
        for(int a = 0; a < 26; ++a) {
            if(a % 2 == 0 || a % 13 == 0) continue;
            for(int b = 0; b < 26; ++b) {
                string tbl = table(a, b);
                string tmp = str;
                for(int i = 0; i < tmp.size(); ++i) 
                    if(tmp[i] != ' ') tmp[i] = tbl[tmp[i]-'a'];
                if(tmp.find("that") != string::npos || tmp.find("this") != string::npos) {
                    cout << tmp << endl;
                    goto next;
                }
            }
        }
next:
        ;
    }
    return 0;
}

C++: //============================================================================
// Name        : aoj0040.cpp
// Author      : afterCmidday
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cctype>
#include <string>

using namespace std;


int gcd(int x,int y){
	if(y == 0){
		return x;
	}
	return gcd(y,x % y);
}
int main(void){
	int a, b, n, i, j;
	string str,ans;
	cin >> n;
	getline(cin,str);
	for(i = 0;i < n;i++){
		ans = "";
		getline(cin,str);
		for(a = 0;;a++){
			if(gcd(a,26) == 1){
				for(b = 0;b < 26;b++){
					string tmp = "";
					for(j = 0;j < str.size();j++){
						if(isalpha(str[j])){
							for(char c = 'a';c <= 'z';c++){
								if((str[j] - 'a') == (a * (c - 'a') + b) % 26){
									tmp += c;
								}
							}
						}else{
							tmp += str[j];
						}
					}
					if(tmp.find("that") != -1 || tmp.find("this") != -1){
						ans = tmp;
						break;
					}
				}
				if(ans != ""){
					break;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
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:;
    }
}