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<cctype>
using namespace std;
#define NON string::npos
int main(){
  int n;
  (cin >> n).ignore();
  while(n--){
    string str;
    getline( cin, str);
    for(int i = 1 ; i < 26 ; i++ ){
      for(int j = 1 ; j < 26 ; j++ ){
        string ret = str;
        for(int k = 0 ; k < ret.size() ; k++ ){
          if(islower(ret[k])) ret[k] = ((ret[k] - 'a') * i + j) % 26 + 'a';
        }
        if(ret.find("that") != NON || ret.find("this") != NON){
          cout << ret << endl;
          i = j = 27;
        }
      }
    }
  }
}

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

using namespace std;

int main(){
	
	string c, str;
	
	bool checker;
	
	int n;
	
	cin >> n;
	cin.ignore();
	
	for(int loop = 0; loop < n; loop++){
		getline(cin, str);
		
		for(int i = 0; i < 26; i++){
			if(i % 2 == 0 || i % 13 == 0){
				continue;
			}
			for(int k = 0; k < 26; k++){
				for(int j = 0; j < 2000; j++){
					if(str[j] == '\0'){
						c[j] = '\0';
						break;
					}else if(str[j] == ' '){
						c[j] = ' ';
					}else{
						c[j] = (i * (str[j] - 'a') + k) % 26 + 'a';
					}
				}
				
				checker = false;
				
				for(int j = 0; j < 2000; j++){
					if(c[j] == '\0'){
						break;
					}
					if(c[j] == 't' && c[j + 1] == 'h'){
						if(c[j + 2] == 'i' && c[j + 3] == 's'){
							checker = true;
							break;
						}else if(c[j + 2] == 'a' && c[j + 3] == 't'){
							checker = true;
							break;
						}
					}
				}
				
				if(checker){
					break;
				}
			}
			if(checker){
				break;
			}
		}
		
		for(int i = 0; i < 2000; i++){
			if(c[i] == '\0'){
				break;
			}
			cout << c[i];
		}
		cout << endl;
	}
	
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<string.h>


#define MAX_STR 257
#define ALFA_NUM 26

using namespace std;

int gcd(int);

int main(){

	int n;
	char str[MAX_STR],fstr[MAX_STR];
	bool flag;
	
	cin>>n;
	
	
	while(n--){
		flag=true;
		//改行がバッファに残っているので捨てる
		fflush(stdin);
		memset(str,'\0',sizeof(str));		
		fgets(str,sizeof(str),stdin);
		
		
		for(int i=0;i<100;i++){
			if(gcd(i)==1){
				for(int j=0;j<27;j++){
				
					memset(fstr,'\0',sizeof(fstr));
					
					for(int k=0;str[k]!='\0' && k<sizeof(str);k++){
						
						if(str[k]!='\n' && str[k]!=' '){
							fstr[k]=((i*(str[k]-'a')+j)%ALFA_NUM)+'a';
						}
						else if(str[k]==' '){
							fstr[k]=str[k];
						}					
					}
					
					if(strstr(fstr,"that")!=NULL||strstr(fstr,"this")!=NULL){
						printf("%s\n",fstr);
						goto Z;
					}
				}
			}
		}
		Z:;
	}
}

int gcd(int n){
	int temp,m;
	m=ALFA_NUM;
	if(n>m){
		temp=n;
		n=m;
		m=temp;
	}
	while(1){
		if(n==0){
			return m;
		}
		temp=n;
		n=m%n;
		m=temp;
	}
}

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

int affine(int word,int A,int B) {
  return (A * word + B) % 26;
}

int main() {
  string str,sentence[256],ans;
  int x[256],afx[256],ansc[256],affans[256],anssize,size,n,alpha,beta,t;
  char convx[256],convans[256],that[5] = {'t','h','a','t','\0'},is[5] = {'t','h','i','s','\0'};
  cin >> n;
  for(int i=0;i<n;i++) {
    t = 0;
    while(cin >> str) {
      sentence[t] = str;
      t++;
      //      cout << sentence[t-1] << endl;
    }
    for(int k=0;k<t;k++) {
      size = sentence[k].size();
      //      cout << size <<endl;
      // size == 4
      if(size == 4) {
	int x[256] = {0},afx[256] = {0};
	char convx[256] = {""};
	for(int i=0;i<size;i++) { //get a word in int[]
	  x[i] = *sentence[k].substr(i,1).c_str() - 97;
	  //  cout << x[i] << endl;
	  //y[i] = x[i] + 97;
	  //cout << y[i] << endl;
	}

	
	for(int ii=0;ii<13;ii++) { //convert a word to affine word
	  for(int j=0;j<26;j++) {
	    for(int m=0;m<size;m++) {
	      if(ii != 6) {
		afx[m] = affine(x[m],2 * ii + 1,j);
		convx[m] = afx[m] +97;
	      }
	    }
	    // cout << convx << endl;
	    if((strcmp(convx,that) == 0) || (strcmp(convx,is) == 0)) {
	      //	      	      cout << "get!get!get!" << endl;
	      alpha = 2 * ii + 1;
	      beta = j;
	      goto NEXT;
	    }
	  }  
	}
     
      }
      // size == 4
    }
  NEXT:
    cout << "alpha = " << alpha << " beta = " << beta << endl;
    /*
      for(int m=0;m<t;m++) {
      cout << sentence[m] << endl;
      }
    */
  
    for(int m=0;m<t;m++) { // convert sentence
      ans = sentence[m];
      anssize = ans.size();
      // cout << "OK" << endl;
      for(int j=0;j<anssize;j++) {
	ansc[j] = *ans.substr(j,1).c_str() - 97;
	//	cout << ansc[j] << endl;
	affans[j] = affine(ansc[j],alpha,beta);
	//cout << affans[j] << endl;
	convans[j] = affans[j] +97;
	//	cout << convans[j] << endl;
      }
      convans[anssize] = '\0';
      cout << convans << " ";
    }
    
    
  }
}

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

char rtable[26];

string affine(const string &s, int a, int b) {
	string ret = s;
	for (int i = 0; i < ret.size(); i++)
		ret[i] = ((ret[i]-'a')*a + b) % 26 + 'a';
	return ret;
}

void setrtable(int a, int b) {
	for (int x = 0; x < 26; x++) {
		int y = (x*a + b) % 26;
		rtable[y] = (char)(x + 'a');
	}
}

int main() {
	int n; cin >> n;
	string s;
	getline(cin, s); // dummy
	for (int i = 0; i < n; i++) {
		getline(cin, s);
		int aa, bb;
		bool found = false;
		for (int a = 1; a < 26 && !found; a += 2) {
			if (a == 13) continue;
			for (int b = 0; b < 26; b++) {
				string a1 = affine("this", a, b);
				string a2 = affine("that", a, b);
				if (s.find(a1) != string::npos || s.find(a2) != string::npos) {
					aa = a, bb = b;
					found = true;
					break;
				}
			}
		}
		setrtable(aa, bb);
		for (int j = 0; j < s.size(); j++) {
			if (s[j] >= 'a' && s[j] <= 'z')
				cout << rtable[s[j] - 'a'];
			else
				cout << s[j];
		}
		cout << endl;
	}
	return 0;
}