import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto s = readln.strip.dup;
		auto n = s.length.to !(int);
		string res;
		foreach (i; 0..n + 1)
		{
			if (i < n)
			{
				s[i] ^= 3;
			}
			if (s.count ("ab") == s.count ("ba"))
			{
				res = s.idup;
			}
			if (i < n)
			{
				s[i] ^= 3;
			}
		}
		writeln (res);
	}
}
