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 <stdio.h>
#include <stack>

using namespace std;


//??¨??¬??????a,b????????????????????????????????¢??°
bool judge(int a, int b){
	int checkTable[26];
	for(int i=0;i<26;i++)checkTable[i] = 0;
	for(int i=0;i < 26;i++){
		if(checkTable[(a*i+b)%26] == 0){
			checkTable[(a*i+b)%26] = 1;
		}else{
			return false;
		}
	}
	return true;
}


int main(){
	int n,length,a,b;
	char buf[300],convert[26],s1,s2,s3,s4;
	bool FLG;

	scanf("%d",&n);
	getchar();
	for(int i=0;i<n;i++){
		fgets(buf,300,stdin);
		length = 0;
		FLG = false;
		//??????4?????????????????¢??????a,b?????????????????????
		for(int k=0;buf[k] != '\0';k++){
			if(buf[k] == ' '){
				if(length == 4){

					s1 = buf[k-4] - 97;
					s2 = buf[k-3] - 97;
					s3 = buf[k-2] - 97;
					s4 = buf[k-1] - 97;

					//this??§??¨??¬
					if(s1 > s4){
						a = s1 - s4;
					}else{
						a = (s1 + 26) -s4;
					}
					b = -1;
					for(int p=0;p<26;p++){
						if((19*a+p)%26==s1){
							b = p;
							if(judge(a,b) && (19*a+b)%26 == s1 && (7*a+b)%26 == s2 && (8*a+b)%26 == s3 && (18*a+b)%26 == s4){
								FLG = true;
								break;
							}
						}
					}
					if(FLG){
						break;
					}

					if(s1 == s4){
						//that??§??¨??¬
						a = -1;
						b = s3;
						for(int p=0;p<26;p++){
							if((19*p+b)%26==s1){
								a = p;
								if(judge(a,b) && (19*a+b)%26 == s1 && (7*a+b)%26==s2){
									FLG = true;
									break;
								}
							}
						}
						if(FLG){
							break;
						}
					}
				}
				length = 0;
			}else if(buf[k+1] == '\0'){
				length++;
				if(length == 4){

					s1 = buf[k-3] - 97;
					s2 = buf[k-2] - 97;
					s3 = buf[k-1] - 97;
					s4 = buf[k] - 97;

					//this??§??¨??¬
					if(s1 > s4){
						a = s1 - s4;
					}else{
						a = (s1 + 26) -s4;
					}
					b = -1;
					for(int p=0;p<26;p++){
						if((19*a+p)%26==s1){
							b = p;
							if(judge(a,b) && (19*a+b)%26 == s1 && (7*a+b)%26 == s2 && (8*a+b)%26 == s3 && (18*a+b)%26 == s4){
								FLG = true;
								break;
							}
						}
					}
					if(FLG){
						break;
					}


					//that??§??¨??¬
					if(s1 == s4){
						a = -1;
						b = s3;
						for(int p=0;p<26;p++){
							if((19*p+b)%26==s1){
								a = p;
								if(judge(a,b) && (19*a+b)%26 == s1 && (7*a+b)%26==s2){
									FLG = true;
									break;
								}
							}
						}
						if(FLG){
							break;
						}
					}
				}
				length = 0;
			}else{
				length++;
			}
		}

		//????????¨?????????
		for(int k = 0; k < 26;k++)convert[(a*k+b)%26] = k;

		for(int k=0;buf[k] != '\0';k++){
			if(buf[k]>=97 && buf[k] <= 122){
				buf[k] = convert[buf[k]-97]+97;
			}
		}
		printf("%s\n",buf);
	}

    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(i = 0;i < str.size();i++){
						if(isalpha(str[i])){
							for(char c = 'a';c <= 'z';c++){
								if((str[i] - 'a') == (a * (c - 'a') + b) % 26){
									tmp += c;
								}
							}
						}else{
							tmp += str[i];
						}
					}
					if(tmp.find("that") != -1 || tmp.find("this") != -1){
						ans = tmp;
						break;
					}
				}
				if(ans != ""){
					break;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

string encrypt(string str, int alpha, int beta){
  int size = str.size();
  string ret = "";

  for(int i=0;i<size;i++){
	if('a' <= str[i] && str[i] <= 'z'){
	  ret += (alpha * (str[i] - 'a') + beta) % 26 + 'a';
	}
  }

  cout << str << " is encrypted to: "<< ret << endl;
  return ret;
}

int main(void){
  string thiss("this");
  string that("that");
  int n;

  cin >> n;
  cin.ignore(); //CR+LF
  for(int i=0;i<n;i++){
	vector<string> strv;
	string str, tmp;
	getline(cin, str);
	int numwords;
	istringstream iss(str);
	int alpha, beta;
	bool decided = false;

	decided = false;
	while(iss >> tmp){
	  strv.push_back(tmp);
	}
	numwords = strv.size();

	for(int j=0;j<numwords;j++){
	  /* test */
	  cout << "checking: " << strv[j] << endl;
	  /* */
	  if(strv[j].size() == 4){
		if(strv[j][0] == strv[j][3]){// strv[j] is a candidate of that
		  cout << "candidate of that" << endl;
		  beta = strv[j][2] - 'a';
		  cout << "beta is " << beta << endl;
		  //calc alpha
		  int k=0;
		  while(strv[j][0] - 'a' +k*26 < beta || (k*26 + strv[j][0] - 'a' - beta) % 19 != 0){ // 19 == t
			k++;
		  }
		  alpha = (k*26+(strv[j][0] - 'a' - beta)) / 19;
		  cout << "alpha is " << alpha << endl;
		  string encrypted = "";
		  encrypted = encrypt("that", alpha, beta);
		  if(strv[j] == encrypted){
			decided = true;
		  }
		}else{// strv[j] is a candidate of this
		  cout << "candidate of this" << endl;
		  tmp = strv[j];
		  if(tmp[0] < tmp[3]) tmp[0] += 26;
		  alpha = tmp[0] - tmp[3];
		  cout << "alpha is " << alpha << endl;
		  if(tmp[3] - 'a' >= alpha * 18 % 26){
			beta = tmp[3] - 'a' - alpha * 18 % 26;
		  }else{
			beta = tmp[3] - 'a' + 26 - alpha * 18 % 26;
		  }
		  cout << "beta is " << beta << endl;
		  string encrypted = encrypt("this", alpha, beta);
		  if(strv[j] == encrypted){
			decided = true;
		  }
		}
	  }
	  if(decided) break;
	}

	//decrypt
	for(int j=0;j<str.size();j++){
	  int k=0;
	  if('a' <= str[j] && str[j] <= 'z'){
		while(str[j]-'a' + k*26 < beta || (k*26 + str[j] - 'a' - beta) % alpha != 0) k++;
		str[j] = ((k*26 + str[j] - 'a' - beta) / alpha) + 'a';
	  }
	}
	cout << str << endl;
  }

  return 0;
}