#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<string>
using namespace std;
map<string,set<string>> G;
map<string,bool> used;
map<string,bool> rec;
vector<string> V;
void dfs(string cur, string aim){
if(used[cur] || rec[aim]) return;
used[cur] = 1;
for(auto i = G[cur].begin(); i != G[cur].end(); i++){
if(*i != aim){
dfs(*i,aim);
}else{
rec[aim] = 1;
return;
}
}
}
int main(){
//input
int n; cin >> n;
for(int i = 0; i < n; i++){
string curVert; cin >> curVert;
V.push_back(curVert);
int m; cin >> m;
while(m--){
string inp; cin >> inp;
G[curVert].insert(inp);
}
if(i != n-1){
string stars;
cin >> stars;
}
}
//work
for(auto i : V){
dfs(i, i);
used.clear();
}
for(auto i : V){
cout << i << (rec[i] ? ": YES" : ": NO") << endl;
}
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPHZlY3Rvcj4KI2luY2x1ZGU8c2V0PgojaW5jbHVkZTxtYXA+CiNpbmNsdWRlPHN0cmluZz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCm1hcDxzdHJpbmcsc2V0PHN0cmluZz4+IEc7Cm1hcDxzdHJpbmcsYm9vbD4gdXNlZDsKbWFwPHN0cmluZyxib29sPiByZWM7CnZlY3RvcjxzdHJpbmc+IFY7Cgp2b2lkIGRmcyhzdHJpbmcgY3VyLCBzdHJpbmcgYWltKXsKICAgaWYodXNlZFtjdXJdIHx8IHJlY1thaW1dKSByZXR1cm47CiAgIHVzZWRbY3VyXSA9IDE7CiAgIGZvcihhdXRvIGkgPSBHW2N1cl0uYmVnaW4oKTsgaSAhPSBHW2N1cl0uZW5kKCk7IGkrKyl7CiAgICAgIGlmKCppICE9IGFpbSl7CiAgICAgICAgIGRmcygqaSxhaW0pOwogICAgICB9ZWxzZXsKICAgICAgICAgcmVjW2FpbV0gPSAxOwogICAgICAgICByZXR1cm47CiAgICAgIH0KICAgfQp9CgppbnQgbWFpbigpewogICAvL2lucHV0CiAgIGludCBuOyBjaW4gPj4gbjsKIC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