#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long LL;
#define pb push_back
const int N = 1e5+10;
inline void solve(){
int m , n , q ; cin >> m >> n >> q ;
map<string , string> ur ; // 密钥对匹配 ;
while(m--){
string a , b ; cin >> a >> b ;
ur[b] = a ;
}
map<string,vector<string>> mp ;
for(int i=0;i<n;i++){
string ip ; cin >> ip ;
int k ; cin >> k ;
while(k--){
string s ; cin >> s ;
mp[s].push_back(ip) ;
int cnt ; cin >> cnt ;
while(cnt--){
string pub ; cin >> pub ;
mp[s].push_back(pub) ;
}
}
}
for(int i=0;i<q;i++){
string usr,ip,pri;cin>>usr>>ip>>pri ;
if(mp.find(usr)==mp.end()){
cout << "No" << endl ;
continue ;
}
auto vec = mp[usr] ;
if(vec[0]!=ip) {
cout << "No" << endl ;
continue ;
}
bool t = false ;
for(int i=1;i<vec.size();i++){
string ts = vec[i] ;
if(ur[pri]==ts){
t = true ;
break ;
}
}
if(t) cout << "Yes" << endl ;
else cout << "No" << endl;
}
}
signed main(){
IOS
int _ = 1;
while(_ --) solve();
return 0;
}