#include using namespace std; // #include // using namespace atcoder; // using mint = modint998244353; using ll = long long; #define fix(x) fixed << setprecision(x) #define rep(i, n) for(int i = 0; i < n; ++i) #define all(x) (x).begin(),(x).end() templatebool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} templatebool chmax(T&a, const T&b){if(a> t; while(t--){ int n; cin >> n; int maxb = 0, minb = INF; bool ok1 = false, ok2 = false; rep(i,n){ string x,y; cin >> x >> y; if(x=="a"){ ok1 = true; for(char c:y){ if(c=='a') ok2 = true; } if(!ok2) chmax(maxb, y.size()); }else{ bool f = true; for(char c:x){ if(c=='a') f = false; } if(f) chmin(minb, x.size()); } } cout << ((ok2 || minb<=maxb) ? "Yes\n":"No\n"); } return 0; }