/* -*- coding: utf-8 -*- * * 3234.cc: No.3234 Infinite Propagation - yukicoder */ #include #include #include using namespace std; /* constant */ const int MAX_L = 200000; const int INF = 1 << 30; /* typedef */ using pii = pair; /* global variables */ char s[MAX_L + 4]; /* subroutines */ pii read() { scanf("%s", s); int cs[2] = {}; for (int i = 0; s[i]; i++) cs[s[i] - 'a']++; return {cs[0], cs[1]}; } /* main */ int main() { int tn; scanf("%d", &tn); while (tn--) { int n; scanf("%d", &n); bool ok = false; int b0 = 0, b1 = INF, b2 = INF; for (int i = 0; i < n; i++) { auto [xa, xb] = read(); auto [ya, yb] = read(); if (xa == 1 && xb == 0) { // 'a' if (ya > 0) ok = true; else b0 = max(b0, yb); } else if (xa == 0 && xb > 0) { // 'bbb..' if (ya > 0) b1 = min(b1, xb); else b2 = min(b2, xb); } } //printf(" b0=%d,b1=%d,b2=%d\n", b0, b1, b2); if (b0 >= b2) b0 = INF; if (b0 >= b1) ok = true; if (ok) puts("Yes"); else puts("No"); } return 0; }