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 <algorithm>
using namespace std;

int gcd(int x, int y);

int main()
{
    int n;
    string s;
    cin >> n;
    while (getline(cin, s))
    {
        bool is_found = false;
        for(int alpha=1; alpha<=26; alpha++)
        {
            if(gcd(alpha, 26) !=1)
            {
                continue;
            }
            for(int beta=0; beta<26; beta++)
            {
                string ans = s;
                for(int i=0; i<ans.size(); i++)
                {
                    if(ans[i] >= 'a' && ans[i] <= 'z')
                    {
                        ans[i] = 'a' + (alpha * (ans[i] -'a') + beta) % 26;
                    }
                    else
                    {

                    }
                }
                if( ans.find("this") != std::string::npos
                 || ans.find("that") != std::string::npos)
                {
                    cout << ans << endl;
                    is_found = true;
                    break;
                }
            }
            if(is_found)
            {
                break;
            }
        }
    }
    return 0;
}

int gcd(int x, int y)
{
    if(x < y)
    {
        swap(x, y);
    }
    while(y > 0)
    {
        int r = x % y;
        x = y;
        y = r;
    }
    return x;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int n,i,j,k;string s,t;cin>>n;
	getline(cin,s);
	while(n--){getline(cin,s);t=s;
		for(i=0;i<99;i++)for(j=0;j<26;j++){
			for(k=0;k<s.size();k++)if(t[k]-32)t[k]=97+(i*s[k]+j)%26;
			if(t.find("this")+1||t.find("that")+1)goto loop;
		}loop:cout<<t<<endl;
	}return 0;
}

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

void encode( const int a, const int b, string& s ){
	for ( unsigned i = 0; i < s.size(); ++i ){
		s[ i ] = static_cast< char >( ( ( s[ i ] - 'a' ) * a + b ) % 26 + 'a' );
	}
}

void decode( const int a, const int b, string& s ){
	string listA = "abcdefghijklmnopqrstuvwxyz", listB;
	for ( unsigned i = 0; i < listA.size(); ++i ){
		listB += static_cast< char >( ( ( listA[ i ] - 'a' ) * a + b ) % 26 + 'a' );
	}
	for ( unsigned i = 0; i < s.size(); ++i ){
		if ( !( s[ i ] >= a && s[ i ] <= 'z' ) ) continue;
		for ( unsigned j = 0; j < listB.size(); ++j ){
			if ( s[ i ] == listB[ j ] ){
				s[ i ] = listA[ j ];
				break;
			}
		}
	}
}

void identifyKeys( int& a, int& b, const string s ){
	for( a = 3; ; ++a ){
		if ( !( a % 2 ) || !( a % 13 ) ) continue;
		for ( b = 0; b < 26; ++b ){
			string sThis = "this", sThat = "that";
			encode( a, b, sThat );
			encode( a, b, sThis );
			if ( s.find( sThat ) != string::npos || s.find( sThis ) != string::npos ){
				return;
			}
		}
	}
}

int main(){
	string s, ws;
	int n;

	cin >> n;
	cin.ignore();

	for ( int i = 0; i < n; ++i ){
		getline( cin, s );
		int aKey = 0, bKey = 0;
		identifyKeys( aKey, bKey, s );
		decode( aKey, bKey, s );
		cout << s << endl;
	}

	return 0;
}

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

int main()
{
	int n;
	std::cin >> n;

	while( n-- )
	{
		std::string s;
		std::cin.ignore();
		std::getline( std::cin, s );

		std::string t( s.size(), ' ' );

		for( int a = 1; a < 26; a += 2 )
		{
			if( a == 13 )
				continue;

			for( int b = 0; b < 26; ++b )
			{
				for( int i = 0; i != s.size(); ++i )
				{
					if( s[i] >= 'a' && s[i] <= 'z' )
					{
						int g = s[i] - 'a';

						t[i] = ( a * g + b ) % 26 + 'a';
					}
				}

				if( t.find( "this" ) != std::string::npos || t.find( "that" ) != std::string::npos )
					goto end;
			}
		}

end:;

		std::cout << t;
	}

	return 0;
}

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

int main()
{
	int n;
	std::cin >> n;
	
	while( n-- ){
		char s[257], t[257];
		char a[26];
		
		fgets( s, 257, stdin );
		
		strcpy( t, s );
		
		for( int i = 1; i <= 26; i += 2 ){
			for( int j = 0; j < 26; j++ ){
				if( i % 13 == 0 ) continue;
				
 				for( int k = 0; k < 26; k++ ){
				 	a[ ( i * k + j ) % 26 ] = k + 'a';
				}
				
				for( int k = 0; k < strlen( t ); k++ ){
					if( s[k] == ' ' || s[k] == '\n' ) continue;
					
					s[k] = a[ t[k] - 'a' ];
				}
				
				if( strstr( s, "that" ) != NULL || strstr( s, "this" ) != NULL ){
					std::cout << s;
				}
				
				strcpy( s, t );
			}
		}
	}

 	return 0;
}

C++: #include<iostream>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cmath>
using namespace std;
int inf = 1000000000;

char affine(char c, int a, int b){
  int x = c - 'a';
  int y = ( a * x + b ) % 26;
  char r = 'a' + y;
  return r;
}

int main(){

  int n;
  cin >> n;
  cin.ignore();
  for(int l=0; l<n; l++){
    string s;
    getline(cin, s);

    for(int i=0; i<50; i++){
      if( i % 2 == 0 || i % 13 == 0 ) continue;
      for(int j=0; j<50; j++){
        string t = "";
        for(int k=0; k<s.size(); k++){
          if( 'a' <= s[k] && s[k] <= 'z' ) t += affine(s[k], i, j);
          else t += s[k];
        }
        for(int k=0; k<t.size()-4; k++){
          if( (t[k] == 't' && t[k+1] == 'h' && t[k+2] == 'a' && t[k+3] == 't') || (t[k] == 't' && t[k+1] == 'h' && t[k+2] == 'i' && t[k+3] == 's') ) cout << t << endl;
        }
      }
    }

  }


  return 0;
}

C++: #include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  string s;
  int n;
  cin>>n;
  getline(cin,s);
  while(n--){
    getline(cin,s);
    r(i,26)r(j,26){
      string t=s;
      r(k,t.size())
        if(t[k]!=' ')t[k]=(t[k-'a']*i+j)%26+'a';
      if(t.find("that")!=string::npos||t.find("this")!=string::npos){
        cout<<t<<endl;
        goto L;
      }
    }L:;
  }
}

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;
}