import std.stdio, std.algorithm, std.array, std.conv, std.typecons; void main() { string[] anss; auto T = readln[0 .. $-1].to!uint; test: foreach (t; 0 .. T) { auto N = readln[0 .. $-1].to!uint; string[][] XYs; foreach (n; 0 .. N) { XYs ~= readln.split; } ulong bbb_lens_max; foreach (XY; XYs) { if (XY[0] == "a") if (XY[1].count("a") != 0) { anss ~= "Yes"; continue test; } else bbb_lens_max = max(bbb_lens_max, XY[1].length); } foreach (XY; XYs) { if (XY[0].count("a") == 0 && XY[0].length <= bbb_lens_max) { anss ~= "Yes"; continue test; } } anss ~= "No"; } foreach (ans; anss) writeln(ans); }