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<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;
	
	scanf("%d",&n);
	
	for(int m=0;m<n;m++){
		flag=true;
		//fgetsの入力がsizeof(str)を超えたら捨てる
		fflush(stdin);
		//memset(str,'\0',sizeof(str));
		
		fgets(str,sizeof(str),stdin);
		
		
		for(int i=0;i<26&&flag==true;i++){
			if(gcd(i)==1){
				for(int j=0;j<26 && flag==true;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]!='\n'){
							fstr[k]=str[k];
						}					
					}
					if(strstr(fstr,"that")!=NULL||strstr(fstr,"this")!=NULL){
						printf("%s\n",fstr);
						flag=false;
					}
				}
			}
		}
	
		//fgetsの入力がsizeof(str)を超えたら捨てる
		//fflush(stdin);
	}
}

int gcd(int n){
	int temp,m;
	m=26;
	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 <vector>
#include <string>
#include <sstream>
using namespace std;

#define DCRPT_MAX 26

int Alpha;
int Beta; // 0 -> 25
int fCnt;

int F( int g ) {
  return ( Alpha * g + Beta ) % 26;
}

char f( char c ) {
  return F( c - 'a' ) + 'a';
}

string decode( string str, int cnt ) {
  for(int i=0; i<str.size(); i++) {
    for(int j=0; j<cnt; j++) {
      str[i] = f( str[i] );
    }
  }

  return str;
}

string Decrypt( string str, int cnt ) {
  
  for(int i=0; i<str.size(); i++) {
    for(int j=0; j<cnt; j++) {
      if( 'a' <= str[i] && str[i] <= 'z') {
	str[i] = f( str[i] );
      }
    }
  }

  return str;
}

bool affineCipher( vector<string> vec ) {
  
  for( Alpha = 1; Alpha < 26; Alpha ++ ) {
    if( Alpha % 2 == 0 || Alpha % 13 == 0 ) continue;
    for( Beta = 0; Beta < 26; Beta ++ ) {
      for(int i = 1; i < DCRPT_MAX; i ++) {
	for(int j = 0; j < vec.size(); j ++) {
	  string dec = decode( vec[j], i );
	  if( dec == "this" || dec == "that" ) {
	    fCnt = i;
	    return true;
	  }
	}
      }
    }
  }
  
  return false;
}


int main() {
  string cryptogram;
  int tcase;
  
  cin >> tcase; cin.ignore();
  
  for( int i = 0; i < tcase; i ++ ) {
    getline( cin, cryptogram );
    
    vector<string> v;
    stringstream ss( cryptogram );

    while(true) {
      string str;
      ss >> str; if( str == "" ) break;
      if( str.size() == 4 ) {
	v.push_back( str );
      }
    }

    if( affineCipher( v ) ) {
      cout << Decrypt( cryptogram, fCnt ) << endl;
    }
  }
  
  return 0;
}

C++: #include<iostream>
#include<string>
#include<sstream>
int calc_alpha(const std::string&w, const char*str)
{
	auto distance = [](char from, char to)
	{
		int result = static_cast<int>(to - from);
		return result + (result < 0 ? 26 : 0);
	};
	int dis1[3], ratio[3];
	for (int j = 0; j < 3; j++)
	{
		dis1[j] = distance(w[j], w[j + 1]);
		int dis2 = distance(str[j], str[j + 1]);
		while (true)
		{
			if (dis1[j] % dis2 == 0)
			{
				ratio[j] = dis1[j] / dis2;
				break;
			}
			dis1[j] += 26;
		}
	}
	return ratio[0] == ratio[1] && ratio[1] == ratio[2] ? ratio[0] : -1;
}
int main()
{
	int n;
	std::cin >> n;
	//std::cin.ignore();
	for (int i = 0; i < n; i++)
	{
		std::string str;
		std::getline(std::cin, str);
		std::stringstream ss(str);
		int alpha, beta;
		for (std::string w; ss >> w;)
		{
			if (w.length() == 4)
			{
				alpha = w[0] == w[3] ? calc_alpha(w, "that") : calc_alpha(w, "this");
				if (alpha != -1)
				{
					beta = static_cast<int>(w[0] - 'a' - ('t' - 'a') * alpha % 26);
					break;
				}
			}
		}
		char deciphered[26];
		for (char j = 'a'; j <= 'z'; j++)
		{
			char ciphered = ((j - 'a') * alpha + beta) % 26 + 'a';
			deciphered[ciphered - 'a'] = j;
		}
		for (auto j : str)
		{
			std::cout << (j == ' ' ? ' ' : deciphered[j - 'a']);
		}
		std::cout << std::endl;
	}
	return 0;
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int alp[12] ={1,3,5,7,9,11,15,17,19,21,23,25};
int main()
{
  string str;
  string temp;
  int n;
  scanf("%d\n",&n);
  for(int i = 0;i < n;i++){
    bool flag = false;
    getline(cin,str);
    temp = str;
    if(!flag){
      for(int j = 0;j <12;j++){//α
	for(int k = 0; k <=26;k++){//β
	  if(!flag&&(temp.find("this") !=string::npos||temp.find("that")!=string::npos)){
	    cout <<temp<<endl;
	    flag = true;
	    break;
	  }
	  for(int l = 0;l <str.length();l++){
	    if(str[l] >= 'a' && str[l] <= 'z'){
	      temp[l] =((((str[l]-'a')*alp[j])+k)%26)+'a';
	    }
	  }
	}
      }
    }
  }
  return 0;
}

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

int conv(int ch, int a, int b) {
  if ( !isalpha(ch) ) return ch;
  int n = ch - 'a';
  return (char)('a' + (a * n + b) % 26);
}

int check(string line, int a, int b) {
  for(int i = 0; i < (int)line.size(); i++)
    line[i] = conv(line[i], a, b);

  return line.find("that") != string::npos ||
    line.find("this") != string::npos;
}

int main() {
  int T; cin >> T >> ws;
  while(T--) {
    string line;
    getline(cin, line);

    for(int a = 0; a < 26; a++)
      for(int b = 0; b < 26; b++)
        if( __gcd(a, b) == 1 ) {
          int res = check(line, a, b);
          if ( res ) {
            for(int i = 0; i < (int)line.size(); i++)
              cout << (char)conv(line[i], a, b);
            cout << endl;
          }
        }
  }
  return 0;
}