#include<bits/stdc++.h>
#define pi pair<int, int>
#define ppi pair<pi, pi>
#define f first
#define s second
using namespace std;
const int N=100005;
int n, m, q, u, v, os, pu, pv, wu, wv, idx;
map<string, int> sid;
string st, su, sv;
int mom[N], W[N], pw[N], tw[N]={0};
inline pi par(int x){
int wu=0;
while(x!=mom[x]){
wu^=pw[x];
x=mom[x];
}
return pi(x, wu);
}
int main(){
std::ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m>>q;
for(int i=0; i<n; i++){
cin>>st;
sid[st]=i;
mom[i]=i;
W[i]=1;
}
pi tmp;
for(int i=0; i<m; i++){
cin>>os>>su>>sv;
u=sid[su];
v=sid[sv];
os--;
tmp=par(u);
pu=tmp.f; wu=tmp.s;
tmp=par(v);
pv=tmp.f; wv=tmp.s;
if(pu!=pv){
if(W[u]>W[v]){
mom[pv]=pu;
W[pu]+=W[pv];
pw[pv]=os^wu^wv;
}
else{
mom[pu]=pv;
W[pv]+=W[pu];
pw[pu]=os^wu^wv;
}
cout<<"YES\n";
}
else{
if(wu^wv==os){
cout<<"YES\n";
}
else cout<<"NO\n";
}
}
for(int i=0; i<n; i++){
u=i;
while(u!=mom[u]){
tw[i]^=pw[u];
u=mom[u];
}
}
for(int i=0; i<q; i++){
cin>>su>>sv;
u=sid[su];
v=sid[sv];
if(par(u).f!=par(v).f){
cout<<"3\n";
}
else if(tw[u]^tw[v]==0){
cout<<"1\n";
}
else{
cout<<"2\n";
}
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBwaSBwYWlyPGludCwgaW50PgojZGVmaW5lIHBwaSBwYWlyPHBpLCBwaT4KI2RlZmluZSBmIGZpcnN0CiNkZWZpbmUgcyBzZWNvbmQKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNvbnN0IGludCBOPTEwMDAwNTsKaW50IG4sIG0sIHEsIHUsIHYsIG9zLCBwdSwgcHYsIHd1LCB3diwgaWR4OwptYXA8c3RyaW5nLCBpbnQ+IHN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