#include #include using namespace std; using namespace atcoder; #define rep(i, n) for(int i=0;i<(n);++i) #define rep1(i, n) for(int i=1;i<=(n);i++) #define ll long long using mint = modint998244353; using P = pair; using lb = long double; using T = tuple; #ifdef LOCAL # include # define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__) #else # define dbg(...) (static_cast(0)) #endif int main() { int t; cin >> t; while(t--) { int n; cin >> n; bool ans = false; int cnt = 0; int mc = 1e9; map mp; rep(i,n) { string x, y; cin >> x >> y; if(x=="a") { for(char c : y) if(c=='a' && y.size()>1) ans=true; if(!ans) { mp[x] = max(mp[x], y); } } else{ bool ex = true; for(char c : x) if(c=='a') ex = false; if(ex) { for(char c : y) if(c=='a') { mp[x] = max(mp[x], y); } } } } if(ans) { cout << "Yes" << endl; } else { string t = mp["a"]; if(t=="" && t!="a") cout << "No" << endl; else{ string r = mp[t]; if(r!="") cout << "Yes" << endl; else{ bool f = false; while(t.size()) { t.pop_back(); string r = mp[t]; if(r!="") { cout << "Yes" << endl; f = true; break; } } if(!f) cout << "No" << endl; } } } } return 0; }