import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.container;
import std.datetime;

char affine(char s, int a, int b) {
	auto c = s - 'a';
	return ((a * c + b) % 26 + 'a').to!char;
}

void main()
{
	auto n = readln.chomp.to!int;
	while (n--) {
		auto str = readln.chomp.map!(to!char).array.split;
		auto target = str.filter!(a=> a.length == 4).array;
		int a, b;
		ll:while (1) {
			foreach (bb; 0..26) {
				foreach (e; target) {
					auto sub = e.map!(x=> affine(x.to!char, a, bb)).array;
					if (sub == "this" || sub == "that") {
						b = bb;
						break ll;
					}
				}
			}
			a++;
		}
		foreach (ref e; str) {
			e = e.map!(x => affine(x.to!char, a, b)).array;
		}
		str.join(" ").writeln;
	}
}