#include<bits/stdc++.h>
using namespace std;
#define eps 1e-9
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ac fstream cin("input.txt");ofstream cout("output.txt");
#define ULL unsigned long long
int vis[1200005]={};
int find(int x){
    if(x==vis[x]){
        return x;
    }
    else{
        return find(vis[x]);
    }
}
void uni(int x,int y){
    x=find(x),y=find(y);
    if(x==y)
        return;
    vis[x]=y;
}
int main()
{IOS;
    int a,b,c;
    while(cin>>a>>b>>c){
        map<string,int>num;
        int cnt=1;
        for(int i=0;i<a;i++){
            string x;
            cin>>x;
            num[x]=cnt++;
        }
        for(int i=1;i<=2*a;i++){
            vis[i]=i;
        }
        for(int i=0;i<b;i++){
            int z;
            string x,y;
            cin>>z>>x>>y;
            int t1=num[x],t2=num[y];
            int tmp1=find(t1*2),tmp2=find(t2*2-1),tmp3=find(t1*2-1),tmp4=find(t2*2);
            if(z==1){
                if(tmp1==tmp2){
                    cout<<"NO"<<endl;
                    con;
                }
                if(tmp3==tmp4){
                    cout<<"NO"<<endl;
                    con;
                }
                cout<<"YES"<<endl;
                uni(t1*2,t2*2);
                uni(t1*2-1,t2*2-1);
            }
            else{
               if(tmp1==tmp4){
                    cout<<"NO"<<endl;
                    con;
                }
                if(tmp3==tmp2){
                    cout<<"NO"<<endl;
                    con;
                }
                cout<<"YES"<<endl;
                  uni(t1*2,t2*2-1);
                uni(t1*2-1,t2*2);
            }
        }
        for(int i=0;i<c;i++){
            string x,y;
            cin>>x>>y;
            int t1=num[x],t2=num[y];
              int tmp1=find(t1*2),tmp2=find(t2*2-1),tmp3=find(t1*2-1),tmp4=find(t2*2);
            if( tmp1==tmp4||tmp2==tmp3 ){
                cout<<1<<endl;
            }
            else if( tmp1==tmp2||tmp3==tmp4 ){
                cout<<2<<endl;
            }
            else{
                cout<<3<<endl;
            }
        }
    }
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define eps 1e-9
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ac fstream cin("input.txt");ofstream cout("output.txt");
#define ULL unsigned long long
int vis[200005]={};
int find(int x){
    if(x!=vis[x]){
        return find(vis[x]);
    }
    else return x;
}
int main()
{IOS;
    int a,b,c;
    while(cin>>a>>b>>c){
        map<string,int>num;
        int cnt=1;
        for(int i=0;i<a;i++){
            string x;
            cin>>x;
            num[x]=cnt++;
        }
        for(int i=1;i<=2*a;i++){
            vis[i]=i;
        }
        for(int i=0;i<b;i++){
            int z;
            string x,y;
            cin>>z>>x>>y;
            int t1=num[x],t2=num[y];
            int tmp1=find(t1*2),tmp2=find(t2*2-1),tmp3=find(t1*2-1),tmp4=find(t2*2);
            if(z==1){
                if(tmp1==tmp2){
                    cout<<"NO"<<endl;
                    con;
                }
                if(tmp3==tmp4){
                    cout<<"NO"<<endl;
                    con;
                }
                cout<<"YES"<<endl;
                if(tmp1!=tmp4){
                vis[tmp1]=tmp4;
                }
                if(tmp3!=tmp2){
                vis[tmp3]=tmp2;
                }
            }
            else{
               if(tmp1==tmp4){
                    cout<<"NO"<<endl;
                    con;
                }
                if(tmp3==tmp2){
                    cout<<"NO"<<endl;
                    con;
                }
                cout<<"YES"<<endl;
                if(tmp1!=tmp2){
                vis[tmp1]=tmp2;
                }
                if(tmp3!=tmp4){
                vis[tmp3]=tmp4;
                }
            }
        }
        for(int i=0;i<c;i++){
            string x,y;
            cin>>x>>y;
            int t1=num[x],t2=num[y];
              int tmp1=find(t1*2),tmp2=find(t2*2-1),tmp3=find(t1*2-1),tmp4=find(t2*2);
            if( tmp1==tmp4||tmp2==tmp3 ){
                cout<<1<<endl;
            }
            else if( tmp1==tmp2||tmp3==tmp4 ){
                cout<<2<<endl;
            }
            else{
                cout<<3<<endl;
            }
        }
    }
return 0;
}


#include <bits/stdc++.h>
#define LL long long
using namespace std;

#define MAXN 100005

int par[MAXN];
int oppo[MAXN]; //与该单词关系相反的一个单词
int n,m,q;

map <string,int> word;

int findset(int r)
{
    if(r!=par[r])
        return par[r]=findset(par[r]);
    return r;
}

int main()
{
    std::ios::sync_with_stdio(false);
    cin >> n >> m >> q;
    for(int i=1; i<=n; i++)
    {
        string str;
        cin >> str;
        word[str]=i;
        par[i]=i;
        oppo[i]=0;
    }
    while(m--)
    {
        int t;
        string x,y;
        cin >> t >> x >> y;
        int u=findset(word[x]);
        int v=findset(word[y]); //找两个单词所对应点的根
        int ou=findset(oppo[u]);
        int ov=findset(oppo[v]);    //找两个单词与其相反的单词所对应点的根
        if(t==1)
        {
            if(u==ov || v==ou)
                puts("NO");
            else
            {
                puts("YES");
                par[u]=v;
                if(ou && ov)
                    par[ou]=ov;
                else if(ou)
                    par[ov]=ou;
                else if(ov)
                    par[ou]=ov;
            }
        }
        else
        {
            if(u==v)
                puts("NO");
            else
            {
                puts("YES");
                if(ou)
                    par[v]=ou;
                else
                    oppo[u]=v;
                if(ov)
                    par[u]=ov;
                else
                    oppo[v]=u;
            }
        }
    }
    while(q--)
    {
        string a,b;
        cin >> a >> b;
        int u=findset(word[a]);
        int v=findset(word[b]);
        int ou=findset(oppo[u]);
        int ov=findset(oppo[v]);
        if(u==v)
            puts("1");
        else
        {
            if(u==ov && v==ou)
                puts("2");
            else
                puts("3");
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define LL long long
using namespace std;

#define MAXN 100005

int par[MAXN];
int oppo[MAXN]; //与该单词关系相反的一个单词
int n,m,q;

map <string,int> word;

int findset(int r)
{
    if(r!=par[r])
        return par[r]=findset(par[r]);
    return r;
}

int main()
{
    std::ios::sync_with_stdio(false);
    cin >> n >> m >> q;
    for(int i=1; i<=n; i++)
    {
        string str;
        cin >> str;
        word[str]=i;
        par[i]=i;
        oppo[i]=0;
    }
    while(m--)
    {
        int t;
        string x,y;
        cin >> t >> x >> y;
        int u=findset(word[x]);
        int v=findset(word[y]); //找两个单词所对应点的根
        int ou=findset(oppo[u]);
        int ov=findset(oppo[v]);    //找两个单词与其相反的单词所对应点的根
        if(t==1)
        {
            if(u==ov || v==ou)
                puts("NO");
            else
            {
                puts("YES");
                par[u]=v;
                if(ou && ov)
                    par[ou]=ov;
                if(ou)
                    oppo[v]=ou;
                if(ov)
                    oppo[u]=ov;
            }
        }
        else
        {
            if(u==v)
                puts("NO");
            else
            {
                puts("YES");
                if(ou)
                    par[v]=ou;
                else
                    oppo[u]=v;
                if(ov)
                    par[u]=ov;
                else
                    oppo[v]=u;
            }
        }
    }
    while(q--)
    {
        string a,b;
        cin >> a >> b;
        int u=findset(word[a]);
        int v=findset(word[b]);
        int ou=findset(oppo[u]);
        int ov=findset(oppo[v]);
        if(u==v)
            puts("1");
        else
        {
            if(u==ov && v==ou)
                puts("2");
            else
                puts("3");
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define LL long long
using namespace std;

#define MAXN 100005

int par[MAXN];
int oppo[MAXN]; //与该单词关系相反的一个单词
int n,m,q;

map <string,int> word;

int findset(int r)
{
    if(r!=par[r])
        return par[r]=findset(par[r]);
    return r;
}

int main()
{
    std::ios::sync_with_stdio(false);
    cin >> n >> m >> q;
    for(int i=1; i<=n; i++)
    {
        string str;
        cin >> str;
        word[str]=i;
        par[i]=i;
        oppo[i]=0;
    }
    while(m--)
    {
        int t;
        string x,y;
        cin >> t >> x >> y;
        int u=findset(word[x]);
        int v=findset(word[y]); //找两个单词所对应点的根
        int ou=findset(oppo[u]);
        int ov=findset(oppo[v]);    //找两个单词与其相反的单词所对应点的根
        if(t==1)
        {
            if(u==ov || v==ou)
                puts("NO");
            else
            {
                puts("YES");
                par[u]=v;
                if(ou && ov)
                    par[ou]=ov;
                //else if(ou)
                    //par[ov]=ou;
                //else if(ov)
                    //par[ou]=ov;
            }
        }
        else
        {
            if(u==v)
                puts("NO");
            else
            {
                puts("YES");
                if(ou)
                    par[v]=ou;
                else
                    oppo[u]=v;
                if(ov)
                    par[u]=ov;
                else
                    oppo[v]=u;
            }
        }
    }
    while(q--)
    {
        string a,b;
        cin >> a >> b;
        int u=findset(word[a]);
        int v=findset(word[b]);
        int ou=findset(oppo[u]);
        int ov=findset(oppo[v]);
        if(u==v)
            puts("1");
        else
        {
            if(u==ov || v==ou)
                puts("2");
            else
                puts("3");
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define LL long long
using namespace std;

#define MAXN 100005

int par[MAXN];
int oppo[MAXN]; //与该单词关系相反的一个单词
int n,m,q;

map <string,int> word;

int findset(int r)
{
    if(r!=par[r])
        return par[r]=findset(par[r]);
    return r;
}

int main()
{
    std::ios::sync_with_stdio(false);
    cin >> n >> m >> q;
    for(int i=1; i<=n; i++)
    {
        string str;
        cin >> str;
        word[str]=i;
        par[i]=i;
        oppo[i]=0;
    }
    while(m--)
    {
        int t;
        string x,y;
        cin >> t >> x >> y;
        int u=findset(word[x]);
        int v=findset(word[y]); //找两个单词所对应点的根
        int ou=findset(oppo[u]);
        int ov=findset(oppo[v]);    //找两个单词与其相反的单词所对应点的根
        if(t==1)
        {
            if(u==ov || v==ou)
                puts("NO");
            else
            {
                puts("YES");
                par[u]=v;
                if(ou && ov)
                    par[ou]=ov;
                //else if(ou)
                    //par[ov]=ou;
                //else if(ov)
                    //par[ou]=ov;
            }
        }
        else
        {
            if(u==v)
                puts("NO");
            else
            {
                puts("YES");
                if(ou)
                    par[v]=ou;
                else
                    oppo[u]=v;
                if(ov)
                    par[u]=ov;
                else
                    oppo[v]=u;
            }
        }
    }
    while(q--)
    {
        string a,b;
        cin >> a >> b;
        int u=findset(word[a]);
        int v=findset(word[b]);
        int ou=findset(oppo[u]);
        int ov=findset(oppo[v]);
        if(u==v)
            puts("1");
        else
        {
            if(u==ov && v==ou)
                puts("2");
            else
                puts("3");
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
using namespace std;
map< string, int >node;
const int maxn = 1e5+7;
int father[maxn];
int relation[maxn];
int finds(int x)
{
  if(father[x]==x)
    {
        return x;
    }
    int order=father[x];
    father[x]=finds(father[x]);
    relation[x]=(relation[x]+relation[order])%2;
    return father[x];
}
int main()
{
    int n,m,q;
    string a;
    scanf( "%d%d%d", &n, &m, &q);
    for(int i = 0; i < n; i++)
    {
        cin >> a;
        node[a] = i;
        father[i] = i;
        relation[i]=0;
    }
    for(int i = 0; i < m; i++)
    {
        int z;
        string a1,a2;
        cin >> z >> a1 >> a2;
        z--;
        int x=node[a1],y=node[a2];
        int x1 = finds(x), x2 = finds(y);
        if(x1!=x2)
        {
            cout<<"YES"<<endl;
            father[x2]=x1;
            relation[x2]=(relation[x]-relation[y]+z+2)%2;
        }
        else
        {
            int p=(relation[x]-relation[y]+2)%2;
            if(p==z)puts("YES");
            else puts("NO");
        }
    }
    while(q--)
    {
        string s1,s2;
        cin>>s1>>s2;
        int x,y;
        x=node[s1];
        y=node[s2];
        int a=finds(x),b=finds(y);
        if(a!=b)puts("3");
        else
        {
            int p=(relation[x]-relation[y]+2)%2;
            printf("%d\n",p+1);
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
int n,m,q;
const int MAXN=1e5+7;
const int mod=1e9+7;
int pre[MAXN],relation[MAXN];
map<string,int>num;
string s1,s2;

int findx(int x)
{
    if(pre[x]==x)
    {
        return x;
    }
    int order=pre[x];
    pre[x]=findx(pre[x]);
    relation[x]=(relation[x]+relation[order])%2;
    return pre[x];
}
int main()
{
    int i;
    scanf("%d%d%d",&n,&m,&q);
    for(i=0;i<n;++i)
    {
        cin>>s1;
        num[s1]=i;
    }
    for(i=0;i<n;++i)
    {
        pre[i]=i;
        relation[i]=0;
    }
    int x,y,z;
    while(m--)
    {
        cin>>z>>s1>>s2;
        z--;
        x=num[s1],y=num[s2];
        int a=findx(x),b=findx(y);
        if(a!=b)//关系还没有建立过
        {
            puts("YES");
            //更新结点值
            pre[b]=a;
            relation[b]=(relation[x]-relation[y]+z+2)%2;
        }
        else//关系已经建立
        {
            int p=(relation[x]-relation[y]+2)%2;//得到关系
            if(p==z)puts("YES");
            else puts("NO");
        }
    }
    while(q--)
    {
        cin>>s1>>s2;
        x=num[s1];
        y=num[s2];
        int a=findx(x),b=findx(y);
        if(a!=b)puts("3");//没建立过联系
        else
        {
            int p=(relation[x]-relation[y]+2)%2;
            printf("%d\n",p+1);
        }
    }

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
using namespace std;
map< string, int >node;
const int maxn = 1e5+7;
int flag = 1;
int father[maxn];
int relation[maxn];
int finds(int x)
{
   if(father[x]==x)
    {
        return x;
    }
    int order=father[x];
    father[x]=finds(father[x]);
    relation[x]=(relation[x]+relation[order])%2;
    return father[x];

}
int main()
{
    int n,m,q;
    string a;
    scanf( "%d%d%d", &n, &m, &q);
    for(int i = 0; i < n; i++)
    {
        cin >> a;
        node[a] = i;
        father[i] = i;
        relation[i]=0;
    }
    for(int i = 0; i < m; i++)
    {
        int z;
        string a1,a2;
        cin >> z >> a1 >> a2;
        int x1 = finds(node[a1]), x2 = finds(node[a2]);
        if(x1!=x2)
        {
            cout<<"YES"<<endl;
            father[x2]=x1;
            if(z == 1)
            {
                relation[node[a2]]=relation[node[a1]];
            }
            else
            {
                relation[node[a2]]=(relation[node[a1]]+1)%2;
            }
        }
        else
        {
            if(z == 1 )
            {
                if(relation[node[a1]] == relation[node[a2]])
                cout<<"YES"<<endl;
                else
                {
                    cout<<"NO"<<endl;
                }
            }
            else
            {
                if((relation[node[a1]]+1)%2 == relation[node[a2]])
                cout<<"YES"<<endl;
                else
                {
                    cout<<"NO"<<endl;
                }
            }
        }
    }
    while(q--)
    {
        string s1,s2;
        cin>>s1>>s2;
        int x,y;
        x=node[s1];
        y=node[s2];
        int a=finds(x),b=finds(y);
        if(a!=b)puts("3");
        else
        {
            if(relation[node[s1]]==relation[node[s2]])
                cout<<"1"<<endl;
            else
            {
                cout<<"2"<<endl;
            }
        }
    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
using namespace std;
map< string, int >node;
const int maxn = 1e5+7;
int flag = 1;
int father[maxn];
int relation[maxn];
int finds(int x)
{
    int r=x;
    while(r!=father[r])
        r=father[r];

    int i=x,j;
    while(father[i]!=r)
    {
        j=father[i];
        father[i]=r;
        i=j;
    }
    return r;

}
int main()
{
    int n,m,q;
    string a;
    scanf( "%d%d%d", &n, &m, &q);
    for(int i = 0; i < n; i++)
    {
        cin >> a;
        node[a] = i;
        father[i] = i;
        relation[i]=0;
    }
    for(int i = 0; i < m; i++)
    {
        int z;
        string a1,a2;
        cin >> z >> a1 >> a2;
        int x1 = finds(node[a1]), x2 = finds(node[a2]);
        if(x1!=x2)
        {
            cout<<"YES"<<endl;
            father[node[a2]]=x1;
            if(z == 1)
            {
                relation[node[a2]]=relation[node[a1]];
            }
            else
            {
                relation[node[a2]]=(relation[node[a1]]+1)%2;
            }
        }
        else
        {
            if(z == 1 )
            {
                if(relation[node[a1]] == relation[node[a2]])
                cout<<"YES"<<endl;
                else
                {
                    cout<<"NO"<<endl;
                }
            }
            else
            {
                if((relation[node[a1]]+1)%2 == relation[node[a2]])
                cout<<"YES"<<endl;
                else
                {
                    cout<<"NO"<<endl;
                }
            }
        }
    }
    while(q--)
    {
        string s1,s2;
        cin>>s1>>s2;
        int x,y;
        x=node[s1];
        y=node[s2];
        int a=finds(x),b=finds(y);
        if(a!=b)puts("3");
        else
        {
            int p=(relation[x]-relation[y]+2)%2;
            printf("%d\n",p+1);
        }
    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
using namespace std;
map< string, int >node;
const int maxn = 1e5+7;
int flag = 1;
int father[maxn];
int relation[maxn];
int finds(int x)
{
  if(father[x]==x)
    {
        return x;
    }
    int order=father[x];
    father[x]=finds(father[x]);
    relation[x]=(relation[x]+relation[order])%2;
    return father[x];
}
int main()
{
    int n,m,q;
    string a;
    scanf( "%d%d%d", &n, &m, &q);
    for(int i = 0; i < n; i++)
    {
        cin >> a;
        node[a] = i;
        father[i] = i;
        relation[i]=0;
    }
    for(int i = 0; i < m; i++)
    {
        int z;
        string a1,a2;
        cin >> z >> a1 >> a2;
        int x1 = finds(node[a1]), x2 = finds(node[a2]);
        if(x1!=x2)
        {
            cout<<"YES"<<endl;
            father[x2]=x1;
            relation[x2]=(relation[node[a1]]-relation[node[a2]]+z+2)%2;
        }
        else
        {
            int p=(relation[node[a1]]-relation[node[a2]]+2)%2;
            if(p==z)puts("YES");
            else puts("NO");
        }
    }
    while(q--)
    {
        string s1,s2;
        cin>>s1>>s2;
        int x,y;
        x=node[s1];
        y=node[s2];
        int a=finds(x),b=finds(y);
        if(a!=b)puts("3");
        else
        {
            int p=(relation[x]-relation[y]+2)%2;
            printf("%d\n",p+1);
        }
    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
using namespace std;
map< string, int >node;
const int maxn = 1e5+7;
int flag = 1;
int father[maxn];
int relation[maxn];
int finds(int x)
{
   int r=x;
    while(r!=father[r])
        r=father[r];

    int i=x,j;
    while(father[i]!=r)
    {
        j=father[i];
        father[i]=r;
        i=j;
    }
    return r;
}
int main()
{
    int n,m,q;
    string a;
    scanf( "%d%d%d", &n, &m, &q);
    for(int i = 0; i < n; i++)
    {
        cin >> a;
        node[a] = i;
        father[i] = i;
        relation[i]=0;
    }
    for(int i = 0; i < m; i++)
    {
        int z;
        string a1,a2;
        cin >> z >> a1 >> a2;
        int x1 = finds(node[a1]), x2 = finds(node[a2]);
        if(x1!=x2)
        {
            cout<<"YES"<<endl;
            father[x2]=x1;
            if(z == 1)
            {
                relation[node[a2]]=relation[node[a1]];
            }
            else
            {
                relation[node[a2]]=(relation[node[a1]]+1)%2;
            }
        }
        else
        {
            if(z == 1 )
            {
                if(relation[node[a1]] == relation[node[a2]])
                cout<<"YES"<<endl;
                else
                {
                    cout<<"NO"<<endl;
                }
            }
            else
            {
                if((relation[node[a1]]+1)%2 == relation[node[a2]])
                cout<<"YES"<<endl;
                else
                {
                    cout<<"NO"<<endl;
                }
            }
        }
    }
    while(q--)
    {
        string s1,s2;
        cin>>s1>>s2;
        int x,y;
        x=node[s1];
        y=node[s2];
        int a=finds(x),b=finds(y);
        if(a!=b)puts("3");
        else
        {
            if(relation[node[s1]]==relation[node[s2]])
                cout<<"1"<<endl;
            else
            {
                cout<<"2"<<endl;
            }
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5+100;

int n, m,q;
int f[MAXN], relation[MAXN];
string s[MAXN];
map <string,int> dic;

int findfather(int x)
{
    if (f[x] == x)
        return x;
    int olfa = f[x];
    f[x] = findfather(f[x]);
    relation[x] = (relation[x] + relation[olfa]) % 2;
    return f[x];
}

int main()
{
    //freopen("F:\\rush.txt", "r", stdin);
    cin >>n >> m >>q;
    for (int i = 1;i <= n;i++)
    {
        cin >> s[i];
        dic[s[i]] = i;
    }
        for (int i = 1; i <= n; i++)
            f[i] = i, relation[i] = 0;
        string s1,s2;
        for (int i = 1; i <= m; i++)
        {
            int z,x,y;
            cin >> z >> s1 >> s2;
            z--;
            x = dic[s1],y = dic[s2];
            int a = findfather(x), b = findfather(y);
            if (a != b)
            {
                f[b] = a;
                relation[b] = (z + relation[x] - relation[y])%2;
                puts("YES");
            }
            else
            {
                int temp = (relation[x] - relation[y] + 2) % 2;
                if (temp != z)
                        puts("NO");
                    else
                        puts("YES");
            }
        }
        for (int i = 1;i <= q;i++)
        {
            cin >> s1>>s2;
            int x = dic[s1],y = dic[s2];
            int r1 = findfather(x),r2 = findfather(y);
            if (r1!=r2)
                puts("3");
            else
            {
                int temp = (relation[x] - relation[y] + 2) % 2;
                printf("%d\n",temp+1);
            }
        }
    return 0;;
}


#include<iostream>
#include<cstring>
#include<string>
#include<map>
using namespace std;
const int maxn = 1e5 + 5;

int n, m, q;
//string s[maxn];
map<string, int> mapp;

int parent[maxn], _rank[maxn], relation[maxn];
int find(int x)
{
	if (parent[x] == x)	return x;
	else return parent[x] = find(parent[x]);   //���ص���find(parent[x])������
}

int main() {
	while (cin >> n >> m >> q) {
		for (int i = 0; i < n; i++) {
			string s;
			mapp[s] = i;
		}
		for (int i = 0; i < n; i++) { parent[i] = i; relation[i] = 0; }
		for (int i = 0; i < m; i++) {
			int k;
			string s1, s2;
			cin >> k >> s1 >> s2;
			int x = mapp[s1], y = mapp[s2];
			int a = find(x), b = find(y);
			if (a != b) {
				parent[b] = a;
				relation[b] = (k - 1 + relation[x] - relation[y]) % 2;
				puts("YES");
			}
			else {
				int temp = (relation[x] - relation[y] + 2) % 2;
				if (temp != k - 1)
					puts("NO");
				else
					puts("YES");
			}
		}
		for (int i = 0; i < q; i++) {
			string s1, s2;
			cin >> s1 >> s2;
			int x = mapp[s1], y = mapp[s2];
			int a = find(x), b = find(y);
			if (a != b) {
				puts("3");
			}
			else {
				int temp = (relation[x] - relation[y] + 2) % 2;
				cout << temp + 1 << endl;
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<string>
#include<map>
using namespace std;
const int maxn = 1e5 + 5;

int n, m, q;
//string s[maxn];
map<string, int> mapp;

int parent[maxn], _rank[maxn], relation[maxn];
int find(int x)
{
	if (parent[x] == x)	return x;
	else return parent[x] = find(parent[x]);   //���ص���find(parent[x])������
}

int main() {
	while (cin >> n >> m >> q) {
		for (int i = 0; i < n; i++) {
			string s;
			mapp[s] = i;
		}
		for (int i = 0; i < n; i++) { parent[i] = i; relation[i] = 0; }
		for (int i = 0; i < m; i++) {
			int k;
			string s1, s2;
			cin >> k >> s1 >> s2;
			int x = mapp[s1], y = mapp[s2];
			int a = find(x), b = find(y);
			if (a != b) {
				parent[b] = a;
				relation[b] = (k - 1 + relation[x] - relation[y]) % 2;
				puts("YES");
			}
			else {
				int temp = (relation[x] - relation[y] + 2) % 2;
				if (temp != k - 1)
					puts("NO");
				else
					puts("YES");
			}
		}
		for (int i = 0; i < q; i++) {
			string s1, s2;
			cin >> s1 >> s2;
			int x = mapp[s1], y = mapp[s2];
			int a = find(x), b = find(y);
			if (a != b) {
				puts("3");
			}
			else {
				int temp = (relation[x] - relation[y] + 2) % 2;
				cout << temp + 1 << endl;
			}
		}
	}
	return 0;
}


//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
using namespace std;
const int maxn = 1e5 + 5;

int n, m, q;
//string s[maxn];
map<string, int> mapp;

int parent[maxn], relation[maxn];
int find(int x)
{
	if (parent[x] == x)
		return x;
	int olfa = parent[x];
	parent[x] = find(parent[x]);
	relation[x] = (relation[x] + relation[olfa]) % 2;
	return parent[x];
}

int main() {
	//freopen("in.txt", "r", stdin);
	while (cin >> n >> m >> q) {
		for (int i = 1; i <= n; i++) {
			string s;
			cin >> s;
			mapp[s] = i;
		}
		for (int i = 1; i <= n; i++) { parent[i] = i; relation[i] = 0; }
		for (int i = 0; i < m; i++) {
			int k;
			string s1, s2;
			cin >> k >> s1 >> s2;
			int x = mapp[s1], y = mapp[s2];
			int a = find(x), b = find(y);
			if (a != b) {
				parent[b] = a;
				relation[b] = (k - 1 + relation[x] - relation[y] + 2) % 2;
				puts("YES");
			}
			else {
				int temp = (relation[x] - relation[y] + 2) % 2;
				if (temp != k - 1)
					puts("NO");
				else
					puts("YES");
			}
		}
		for (int i = 0; i < q; i++) {
			string s1, s2;
			cin >> s1 >> s2;
			int x = mapp[s1], y = mapp[s2];
			int a = find(x), b = find(y);
			if (a != b) {
				puts("3");
			}
			else {
				int temp = (relation[x] - relation[y] + 2) % 2;
				cout << temp + 1 << endl;
			}
		}
	}
	return 0;
}


/*********** [ scopeInfinity ] ******************/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vll;
typedef std::vector<int> vi;

#define endl '\n'
#define mp make_pair
#define pb(x) push_back((x))
#define what_is(x) cerr << #x << " is " << x << endl;

ll MOD = 1e9+7;
ll INF = LLONG_MAX;

vector<string> &split(const std::string &s, char delim, vector<string> &e) {
    stringstream ss(s);
    string item;
    while(getline(ss, item, delim))
        e.push_back(item);
    return e;
}

ll Pow(ll a ,ll b ,ll Mo){
    ll ans = 1;
    for (; b; b >>= 1, a = a * a % Mo)
        if (b&1) ans = ans * a % Mo;
    return ans;
}

vector<int> Zfunc(string &s) {
    int n=s.length();
    vector<int> z(n,0);
    for(int i=1,l=0,r=0;i<n;i++) {
        if(i<=r)
            z[i] = min(z[i-l],r-i+1);
        while(i+z[i]<n && s[i+z[i]]==s[z[i]])
            z[i]++;
        if(r<i+z[i]-1)
            l=i,r=i+z[i]-1;
    }
    return z;
}

ll solve() {

	return 0;
}
std::vector<ll> parent;
std::vector<ll> oppos;
int root(int c) {
    if(c>=0) {
        int op =oppos[c];
        while(parent[c]!=-1){
            c=parent[c];
            if(op==-1)
                op=oppos[c];
        }
        oppos[c]=op;
    }
    return c;
}
int makeSame(int a,int  b) {
    a=root(a);
    b=root(b);
    if(a==b)
        return 1;
    int o1,o2;
    o1=root(oppos[a]);
    o2=root(oppos[b]);
    if(o1==b || o2==a)
        return 0;
        parent[a]=b;
    if(o1!=-1 && o2!=-1)
        makeSame(o1,o2);
    return 1;
}
int isOpp(int a,int b) {
    a=root(a);
    b=root(b);
    int o1,o2;
    o1=root(oppos[a]);
    o2=root(oppos[b]);
    if(o1==b || o2==a)
        return 1;
    return 0;

}
int isSame(int a,int b) {
    return root(a)==root(b);
}

int setOpposite(int a,int b) {
    a=root(a);
    b=root(b);
    if(a==b) {
        //same
        return 0;
    } else {
        int o;
        o=oppos[b];
        if(o!=-1)
        makeSame(a,o);
        o=oppos[a];
        if(o!=-1)
        makeSame(b,o);
        oppos[a]=b;
        oppos[b]=a;

        return 1;
    }
}

int main(int argc, char const *argv[])
{
	std::ios::sync_with_stdio(false);cin.tie(0);
	// cout<<fixed<<setprecision(1);
	ll n,m,q;
    cin>>n>>m>>q;
    map<string,ll> M;
    parent.resize(n,-1);
    oppos.resize(n,-1);
    for (int i = 0; i < n; ++i)
    {
        string s;
        cin>>s;
        M[s]=i;
    }
    for (int i = 0; i < m; ++i)
    {
        int t;
        string a,b;
        cin>>t>>a>>b;

            int ai= M[a];
            int bi= M[b];

        if(t==1) {
            if(makeSame(ai,bi))
                cout<<"YES\n";
            else
                cout<<"NO\n";
        } else {
            if(setOpposite(ai,bi))
                cout<<"YES\n";
            else
                cout<<"NO\n";
        }
    }
    for (int i = 0; i < q; ++i)
    {
         string a,b;
        cin>>a>>b;

            int ai= M[a];
            int bi= M[b];
            if(isSame(ai,bi))
                cout<<"1\n";
            else if(isOpp(ai,bi))
                cout<<"2\n";
            else cout<<"3\n";
    }
	return 0;
}


/*********** [ scopeInfinity ] ******************/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vll;
typedef std::vector<int> vi;

#define endl '\n'
#define mp make_pair
#define pb(x) push_back((x))
#define what_is(x) cerr << #x << " is " << x << endl;

ll MOD = 1e9+7;
ll INF = LLONG_MAX;

vector<string> &split(const std::string &s, char delim, vector<string> &e) {
    stringstream ss(s);
    string item;
    while(getline(ss, item, delim))
        e.push_back(item);
    return e;
}

ll Pow(ll a ,ll b ,ll Mo){
    ll ans = 1;
    for (; b; b >>= 1, a = a * a % Mo)
        if (b&1) ans = ans * a % Mo;
    return ans;
}

vector<int> Zfunc(string &s) {
    int n=s.length();
    vector<int> z(n,0);
    for(int i=1,l=0,r=0;i<n;i++) {
        if(i<=r)
            z[i] = min(z[i-l],r-i+1);
        while(i+z[i]<n && s[i+z[i]]==s[z[i]])
            z[i]++;
        if(r<i+z[i]-1)
            l=i,r=i+z[i]-1;
    }
    return z;
}

ll solve() {

	return 0;
}
std::vector<ll> parent;
std::vector<ll> oppos;
int root(int c) {
    if(c>=0) {
        int op =oppos[c];
        while(parent[c]!=-1){
            c=parent[c];
            if(op==-1)
                op=oppos[c];
        }
        oppos[c]=op;
    }
    return c;
}
int makeSame(int a,int  b) {
    a=root(a);
    b=root(b);
    if(a==b)
        return 1;
    int o1,o2;
    o1=root(oppos[a]);
    o2=root(oppos[b]);
    if(o1==b || o2==a)
        return 0;
    if(a>b)
        swap(a,b);
    parent[a]=b;

    if(o1!=-1 && o2!=-1)
        makeSame(o1,o2);
    return 1;
}
int isOpp(int a,int b) {
    a=root(a);
    b=root(b);
    int o1,o2;
    o1=root(oppos[a]);
    o2=root(oppos[b]);
    if(o1==b || o2==a)
        return 1;
    return 0;

}
int isSame(int a,int b) {
    return root(a)==root(b);
}

int setOpposite(int a,int b) {
    a=root(a);
    b=root(b);
    if(a==b) {
        //same
        return 0;
    } else {
        int o;
        o=oppos[b];
        if(o!=-1)
        makeSame(a,o);
        o=oppos[a];
        if(o!=-1)
        makeSame(b,o);
        oppos[a]=b;
        oppos[b]=a;
        root(a);
        root(b);
        return 1;
    }
}

int main(int argc, char const *argv[])
{
	std::ios::sync_with_stdio(false);cin.tie(0);
	// cout<<fixed<<setprecision(1);
	ll n,m,q;
    cin>>n>>m>>q;
    map<string,ll> M;
    parent.resize(n,-1);
    oppos.resize(n,-1);
    for (int i = 0; i < n; ++i)
    {
        string s;
        cin>>s;
        M[s]=i;
    }
    for (int i = 0; i < m; ++i)
    {
        int t;
        string a,b;
        cin>>t>>a>>b;

            int ai= M[a];
            int bi= M[b];

        if(t==1) {
            if(makeSame(ai,bi))
                cout<<"YES\n";
            else
                cout<<"NO\n";
        } else {
            if(setOpposite(ai,bi))
                cout<<"YES\n";
            else
                cout<<"NO\n";
        }
    }
    for (int i = 0; i < q; ++i)
    {
         string a,b;
        cin>>a>>b;

            int ai= M[a];
            int bi= M[b];
            if(isSame(ai,bi))
                cout<<"1\n";
            else if(isOpp(ai,bi))
                cout<<"2\n";
            else cout<<"3\n";
    }
	return 0;
}


/*********** [ scopeInfinity ] ******************/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vll;
typedef std::vector<int> vi;

#define endl '\n'
#define mp make_pair
#define pb(x) push_back((x))
#define what_is(x) cerr << #x << " is " << x << endl;

ll MOD = 1e9+7;
ll INF = LLONG_MAX;

vector<string> &split(const std::string &s, char delim, vector<string> &e) {
    stringstream ss(s);
    string item;
    while(getline(ss, item, delim))
        e.push_back(item);
    return e;
}

ll Pow(ll a ,ll b ,ll Mo){
    ll ans = 1;
    for (; b; b >>= 1, a = a * a % Mo)
        if (b&1) ans = ans * a % Mo;
    return ans;
}

vector<int> Zfunc(string &s) {
    int n=s.length();
    vector<int> z(n,0);
    for(int i=1,l=0,r=0;i<n;i++) {
        if(i<=r)
            z[i] = min(z[i-l],r-i+1);
        while(i+z[i]<n && s[i+z[i]]==s[z[i]])
            z[i]++;
        if(r<i+z[i]-1)
            l=i,r=i+z[i]-1;
    }
    return z;
}

ll solve() {

	return 0;
}
std::vector<ll> parent;
std::vector<ll> oppos;
int root(int c) {
    if(c>=0) {
        int op =oppos[c];
        while(parent[c]!=-1){
            c=parent[c];
            if(op==-1)
                op=oppos[c];
        }
        oppos[c]=op;
    }
    return c;
}
int makeSame(int a,int  b) {
    a=root(a);
    b=root(b);
    if(a==b)
        return 1;
    int o1,o2;
    o1=root(oppos[a]);
    o2=root(oppos[b]);
    if(o1==b || o2==a)
        return 0;
    if(a>b)
        swap(a,b);
    parent[a]=b;

    if(o1!=-1 && o2!=-1)
        makeSame(o1,o2);
    root(a);
    root(b);
    return 1;
}
int isOpp(int a,int b) {
    a=root(a);
    b=root(b);
    int o1,o2;
    o1=root(oppos[a]);
    o2=root(oppos[b]);
    if(o1==b || o2==a)
        return 1;
    return 0;

}
int isSame(int a,int b) {
    return root(a)==root(b);
}

int setOpposite(int a,int b) {
    a=root(a);
    b=root(b);
    if(a==b) {
        //same
        return 0;
    } else {
        int o;
        o=oppos[b];
        if(o!=-1)
        assert(makeSame(a,o));
        o=oppos[a];
        if(o!=-1)
        assert(makeSame(b,o));
        oppos[a]=b;
        oppos[b]=a;
        root(a);
        root(b);
        return 1;
    }
}

int main(int argc, char const *argv[])
{
	std::ios::sync_with_stdio(false);cin.tie(0);
	// cout<<fixed<<setprecision(1);
	ll n,m,q;
    cin>>n>>m>>q;
    map<string,ll> M;
    parent.resize(n,-1);
    oppos.resize(n,-1);
    for (int i = 0; i < n; ++i)
    {
        string s;
        cin>>s;
        M[s]=i;
    }
    for (int i = 0; i < m; ++i)
    {
        int t;
        string a,b;
        cin>>t>>a>>b;

            int ai= M[a];
            int bi= M[b];

        if(t==1) {
            if(makeSame(ai,bi))
                cout<<"YES\n";
            else
                cout<<"NO\n";
        } else {
            if(setOpposite(ai,bi))
                cout<<"YES\n";
            else
                cout<<"NO\n";
        }
    }
    for (int i = 0; i < q; ++i)
    {
         string a,b;
        cin>>a>>b;

            int ai= M[a];
            int bi= M[b];
            if(isSame(ai,bi))
                cout<<"1\n";
            else if(isOpp(ai,bi))
                cout<<"2\n";
            else cout<<"3\n";
    }
	return 0;
}


/*********** [ scopeInfinity ] ******************/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vll;
typedef std::vector<int> vi;

#define endl '\n'
#define mp make_pair
#define pb(x) push_back((x))
#define what_is(x) cerr << #x << " is " << x << endl;

ll MOD = 1e9+7;
ll INF = LLONG_MAX;

vector<string> &split(const std::string &s, char delim, vector<string> &e) {
    stringstream ss(s);
    string item;
    while(getline(ss, item, delim))
        e.push_back(item);
    return e;
}

ll Pow(ll a ,ll b ,ll Mo){
    ll ans = 1;
    for (; b; b >>= 1, a = a * a % Mo)
        if (b&1) ans = ans * a % Mo;
    return ans;
}

vector<int> Zfunc(string &s) {
    int n=s.length();
    vector<int> z(n,0);
    for(int i=1,l=0,r=0;i<n;i++) {
        if(i<=r)
            z[i] = min(z[i-l],r-i+1);
        while(i+z[i]<n && s[i+z[i]]==s[z[i]])
            z[i]++;
        if(r<i+z[i]-1)
            l=i,r=i+z[i]-1;
    }
    return z;
}

ll solve() {

	return 0;
}
std::vector<ll> parent;
std::vector<ll> oppos;
int root(int c) {
    if(c>=0)
    while(parent[c]!=-1){
        c=parent[c];
    }
    return c;
}
int makeSame(int a,int  b) {
    a=root(a);
    b=root(b);
    if(a==b)
        return 1;
    int o1,o2;
    o1=root(oppos[a]);
    o2=root(oppos[b]);
    if(o1==b || o2==a)
        return 0;
    if(a!=b) {
        parent[a]=b;
    }
    if(o1!=-1 && o2!=-1)
        makeSame(o1,o2);
    return 1;
}
int isOpp(int a,int b) {
    a=root(a);
    b=root(b);
    int o1,o2;
    o1=root(oppos[a]);
    o2=root(oppos[b]);
    if(o1==b || o2==a)
        return 1;
    return 0;

}
int isSame(int a,int b) {
    return root(a)==root(b);
}

int setOpposite(int a,int b) {
    a=root(a);
    b=root(b);
    if(a==b) {
        //same
        return 0;
    } else {
        int o;
        o=oppos[b];
        if(o!=-1)
        makeSame(a,o);
        o=oppos[a];
        if(o!=-1)
        makeSame(b,o);
        oppos[a]=b;
        oppos[b]=a;

        return 1;
    }
}

int main(int argc, char const *argv[])
{
	std::ios::sync_with_stdio(false);cin.tie(0);
	// cout<<fixed<<setprecision(1);
	ll n,m,q;
    cin>>n>>m>>q;
    map<string,ll> M;
    parent.resize(n,-1);
    oppos.resize(n,-1);
    for (int i = 0; i < n; ++i)
    {
        string s;
        cin>>s;
        M[s]=i;
    }
    for (int i = 0; i < m; ++i)
    {
        int t;
        string a,b;
        cin>>t>>a>>b;

            int ai= M[a];
            int bi= M[b];

        if(t==1) {
            if(makeSame(ai,bi))
                cout<<"YES\n";
            else
                cout<<"NO\n";
        } else {
            if(setOpposite(ai,bi))
                cout<<"YES\n";
            else
                cout<<"NO\n";
        }
    }
    for (int i = 0; i < q; ++i)
    {
         string a,b;
        cin>>a>>b;

            int ai= M[a];
            int bi= M[b];
            if(isSame(ai,bi))
                cout<<"1\n";
            else if(isOpp(ai,bi))
                cout<<"2\n";
            else cout<<"3\n";
    }
	return 0;
}


/*********** [ scopeInfinity ] ******************/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vll;
typedef std::vector<int> vi;

#define endl '\n'
#define mp make_pair
#define pb(x) push_back((x))
#define what_is(x) cerr << #x << " is " << x << endl;

ll MOD = 1e9+7;
ll INF = LLONG_MAX;

vector<string> &split(const std::string &s, char delim, vector<string> &e) {
    stringstream ss(s);
    string item;
    while(getline(ss, item, delim))
        e.push_back(item);
    return e;
}

ll Pow(ll a ,ll b ,ll Mo){
    ll ans = 1;
    for (; b; b >>= 1, a = a * a % Mo)
        if (b&1) ans = ans * a % Mo;
    return ans;
}

vector<int> Zfunc(string &s) {
    int n=s.length();
    vector<int> z(n,0);
    for(int i=1,l=0,r=0;i<n;i++) {
        if(i<=r)
            z[i] = min(z[i-l],r-i+1);
        while(i+z[i]<n && s[i+z[i]]==s[z[i]])
            z[i]++;
        if(r<i+z[i]-1)
            l=i,r=i+z[i]-1;
    }
    return z;
}

ll solve() {

	return 0;
}
std::vector<ll> parent;
std::vector<ll> oppos;
int root(int c) {
    if(c>=0) {
        int op =oppos[c];
        while(parent[c]!=-1){
            c=parent[c];
            if(op==-1)
                op=oppos[c];
        }
        oppos[c]=op;
    }
    return c;
}
int makeSame(int a,int  b) {
    a=root(a);
    b=root(b);
    if(a==b)
        return 1;
    int o1,o2;
    o1=root(oppos[a]);
    o2=root(oppos[b]);
    if(o1==b || o2==a)
        return 0;
    if(a>b)
        swap(a,b);
    parent[a]=b;

    if(o1!=-1 && o2!=-1)
        makeSame(o1,o2);
    return 1;
}
int isOpp(int a,int b) {
    a=root(a);
    b=root(b);
    int o1,o2;
    o1=root(oppos[a]);
    o2=root(oppos[b]);
    if(o1==b || o2==a)
        return 1;
    return 0;

}
int isSame(int a,int b) {
    return root(a)==root(b);
}

int setOpposite(int a,int b) {
    a=root(a);
    b=root(b);
    if(a==b) {
        //same
        return 0;
    } else {
        int o;
        o=oppos[b];
        if(o!=-1)
        assert(makeSame(a,o));
        o=oppos[a];
        if(o!=-1)
        assert(makeSame(b,o));
        oppos[a]=b;
        oppos[b]=a;
        root(a);
        root(b);
        return 1;
    }
}

int main(int argc, char const *argv[])
{
	std::ios::sync_with_stdio(false);cin.tie(0);
	// cout<<fixed<<setprecision(1);
	ll n,m,q;
    cin>>n>>m>>q;
    map<string,ll> M;
    parent.resize(n,-1);
    oppos.resize(n,-1);
    for (int i = 0; i < n; ++i)
    {
        string s;
        cin>>s;
        M[s]=i;
    }
    for (int i = 0; i < m; ++i)
    {
        int t;
        string a,b;
        cin>>t>>a>>b;

            int ai= M[a];
            int bi= M[b];

        if(t==1) {
            if(makeSame(ai,bi))
                cout<<"YES\n";
            else
                cout<<"NO\n";
        } else {
            if(setOpposite(ai,bi))
                cout<<"YES\n";
            else
                cout<<"NO\n";
        }
    }
    for (int i = 0; i < q; ++i)
    {
         string a,b;
        cin>>a>>b;

            int ai= M[a];
            int bi= M[b];
            if(isSame(ai,bi))
                cout<<"1\n";
            else if(isOpp(ai,bi))
                cout<<"2\n";
            else cout<<"3\n";
    }
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;
const int N=1e5+10;
int father[N],b[N];
map<string,int> mp;
int Find(int x)
{
    if(father[x]!=x)
        return father[x]= Find(father[x]);
    return x;
}
int main()
{
    int n,m,q,i,d;
    char str[100],str1[100],str2[100];
    for(i=0; i<=1e5; i++)
        father[i]=i;
    cin>>n>>m>>q;
    for(i=0; i<n; i++)
    {
        scanf("%s",str);
        mp[str]=i+1;
    }
    for(i=0; i<m; i++)
    {
        scanf("%d%s%s",&d,str1,str2);
        int fx=Find(mp[str1]);
        int fy=Find(mp[str2]);
        int x=Find(b[fx]);
        int y=Find(b[fy]);
        if(d==1)
        {
            if(x!=fy)
            {
                if(fx!=fy)
                {
                     father[fy]=fx;
                     if(x&&y) father[y]=x;
                     if(!x) b[fx]=y;
                }
                printf("YES\n");
            }
            else
                printf("NO\n");
        }
        else
        {
            if(fx==fy)
                printf("NO\n");
            else
            {
                 if(x)  father[fy]=x;
                 else b[fy]=fx;
                 if(y) father[fx]=y;
                 else b[fx]=fy;

                printf("YES\n");
            }
        }
    }
    for(i=0; i<q; i++)
    {
        scanf("%s%s",str1,str2);
        int fx=Find(mp[str1]);
        int fy=Find(mp[str2]);
        int x=Find(b[fx]);
        int y=Find(b[fy]);
        if(fx==fy)
            printf("1\n");
        else if(x==fy||y==fx)
            printf("2\n");
        else
            printf("3\n");
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;
const int N=1e5+10;
int father[N],b[N];
map<string,int> mp;
int Find(int x)
{
    if(father[x]!=x)
        return father[x]= Find(father[x]);
    return x;
}
int main()
{
    int n,m,q,i,d;
    char str[100],str1[100],str2[100];
    for(i=0; i<=1e5; i++)
        father[i]=i;
    cin>>n>>m>>q;
    for(i=0; i<n; i++)
    {
        scanf("%s",str);
        mp[str]=i+1;
    }
    for(i=0; i<m; i++)
    {
        scanf("%d%s%s",&d,str1,str2);
        int x=mp[str1];
        int y=mp[str2];
        int fx=Find(x);
        int fy=Find(y);
        if(d==1)
        {
            if(b[fx]!=fy)
            {
                if(fx!=fy)
                {
                    father[fy]=fx;
                    if(!b[fx])
                    {
                        b[fx]=b[fy];
                        b[b[fy]]=fx;
                    }
                    if(b[fx]&&b[fy])
                    {
                         father[b[fx]]=b[fy];
                         if(!b[b[fy]])
                         {
                             b[b[fy]]=b[b[fx]];
                             b[b[b[fx]]]=b[b[fy]];
                         }
                    }
                }
                printf("YES\n");
            }
            else
                printf("NO\n");
        }
        else
        {
            if(fx==fy)
                printf("NO\n");
            else
            {
                if(b[fx]!=0&&b[fx]!=fy)
                {
                    father[fy]=b[fx];
                    if(!b[b[fx]])
                    {
                        b[b[fx]]=b[fy];
                        b[b[fy]]=b[fx];
                    }
                }
                if(b[fy]!=0&&b[fy]!=fx)
                {
                    father[fx]=b[fy];
                    if(!b[b[fy]])
                    {
                        b[b[fy]]=b[fx];
                        b[b[fx]]=b[fy];
                    }
                }
                if(b[fy]==0&&b[fx]==0)
                {
                    b[fx]=fy;
                    b[fy]=fx;
                }
                printf("YES\n");
            }
        }
    }
    for(i=0; i<q; i++)
    {
        scanf("%s%s",str1,str2);
        int fx=Find(mp[str1]);
        int fy=Find(mp[str2]);
        if(fx==fy)
            printf("1\n");
        else if(b[fx]==fy)
            printf("2\n");
        else
            printf("3\n");
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;
const int N=1e5+10;
int father[N],b[N];
map<string,int> mp;
int Find(int x)
{
      if(father[x]!=x)
         return father[x] = Find(father[x]);
        return x;
}
int main()
{
    int n,m,q,i,d;
    char str[100],str1[100],str2[100];
    for(i=0; i<=1e5; i++)
        father[i]=i;
    cin>>n>>m>>q;
    for(i=0; i<n; i++)
    {
        scanf("%s",str);
        mp[str]=i+1;
    }
    for(i=0; i<m; i++)
    {
        scanf("%d%s%s",&d,str1,str2);
        int x=mp[str1];
        int y=mp[str2];
        int fx=Find(x);
        int fy=Find(y);
        if(d==1)
        {
            if(b[fx]!=fy)
            {
                if(fx!=fy)
                {
                    father[fy]=fx;
                    if(b[fx]==0){
                    b[fx]=b[fy];
                    b[b[fy]]=fx;}
                }
                printf("YES\n");
            }
            else
            {
                printf("NO\n");
            }
        }
        else
        {
            if(fx==fy||b[fx]==b[fy]&&b[fx]!=0)
            {
                printf("NO\n");
            }
            else {
                 if(b[fx]!=0&&b[fx]!=fy)
                 {
                     father[fy]=b[fx];
                     if(b[b[fx]]==0){
                     b[b[fx]]=b[fy];
                     b[b[fy]]=b[fx];
                     }
                 }
                 if(b[fy]!=0&&b[fy]!=fx)
                 {
                     father[fx]=b[fy];
                     if(b[b[fy]]==0){
                     b[b[fy]]=b[fx];
                     b[b[fx]]=b[fy];
                    }
                 }
                 if(b[fy]==0&&b[fx]==0)
                {
                   b[fx]=fy;
                    b[fy]=fx;
                 }
                 printf("YES\n");
            }
        }
    }
    /*
     for(i=1;i<=n;i++)
    {
         printf("%d ",father[i]);
    }
        printf("\n");
    for(i=1;i<=n;i++)
    {
         printf("%d ",b[i]);
    }
*/
    for(i=0;i<q;i++)
    {
         scanf("%s%s",str1,str2);
          int fx=Find(mp[str1]);
          int fy=Find(mp[str2]);
          if(fx==fy)
            printf("1\n");
          else if(b[fx]==fy)
                printf("2\n");
            else
               printf("3\n");
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;
const int N=1e5+10;
int father[N],b[N];
map<string,int> mp;
int Find(int x)
{
      if(father[x]!=x)
         return father[x] = Find(father[x]);
        return x;
}
int main()
{
    int n,m,q,i,d;
    char str[100],str1[100],str2[100];
    for(i=0; i<=1e5; i++)
        father[i]=i;
    cin>>n>>m>>q;
    for(i=0; i<n; i++)
    {
        scanf("%s",str);
        mp[str]=i+1;
    }
    for(i=0; i<m; i++)
    {
        scanf("%d%s%s",&d,str1,str2);
        int x=mp[str1];
        int y=mp[str2];
        int fx=Find(x);
        int fy=Find(y);
        if(d==1)
        {
            if(b[fx]!=fy)
            {
                if(fx!=fy)
                {
                    father[fy]=fx;
                    if(b[fx]==0){
                    b[fx]=b[fy];
                    b[b[fy]]=fx;}
                }
                printf("YES\n");
            }
            else
            {
                printf("NO\n");
            }
        }
        else
        {
            if(fx==fy)
            {
                printf("NO\n");
            }
            else {
                 if(b[fx]!=0&&b[fx]!=fy)
                 {
                     father[fy]=b[fx];
                     if(b[b[fx]]==0){
                     b[b[fx]]=b[fy];
                     b[b[fy]]=b[fx];
                     }
                 }
                 if(b[fy]!=0&&b[fy]!=fx)
                 {
                     father[fx]=b[fy];
                     if(b[b[fy]]==0){
                     b[b[fy]]=b[fx];
                     b[b[fx]]=b[fy];
                    }
                 }
                 if(b[fy]==0&&b[fx]==0)
                {
                   b[fx]=fy;
                    b[fy]=fx;
                 }
                 printf("YES\n");
            }
        }
    }
    /*
     for(i=1;i<=n;i++)
    {
         printf("%d ",father[i]);
    }
        printf("\n");
    for(i=1;i<=n;i++)
    {
         printf("%d ",b[i]);
    }
*/
    for(i=0;i<q;i++)
    {
         scanf("%s%s",str1,str2);
          int fx=Find(mp[str1]);
          int fy=Find(mp[str2]);
          if(fx==fy)
            printf("1\n");
          else if(b[fx]==fy)
                printf("2\n");
            else
               printf("3\n");
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;
const int N=1e5+10;
int father[N],b[N];
map<string,int> mp;
int Find(int x)
{
      if(father[x]!=x)
         return father[x] = Find(father[x]);
        return x;
}
int main()
{
    int n,m,q,i,d;
    char str[100],str1[100],str2[100];
    for(i=0; i<=1e5; i++)
        father[i]=i;
    cin>>n>>m>>q;
    for(i=0; i<n; i++)
    {
        scanf("%s",str);
        mp[str]=i+1;
    }
    for(i=0; i<m; i++)
    {
        scanf("%d%s%s",&d,str1,str2);
        int x=mp[str1];
        int y=mp[str2];
        int fx=Find(x);
        int fy=Find(y);
        if(d==1)
        {
            if(b[fx]!=fy)
            {
                if(fx!=fy)
                {
                    father[fy]=fx;
                    if(b[fx]==0){
                    b[fx]=b[fy];
                    b[b[fy]]=fx;}
                }
                printf("Yes\n");
            }
            else
            {
                printf("No\n");
            }
        }
        else
        {
            if(fx==fy)
            {
                printf("No\n");
            }
            else {
                 if(b[fx]!=0&&b[fx]!=fy)
                 {
                     father[fy]=b[fx];
                     if(b[b[fx]]==0){
                     b[b[fx]]=b[fy];
                     b[b[fy]]=b[fx];
                     }
                 }
                 if(b[fy]!=0&&b[fy]!=fx)
                 {
                     father[fx]=b[fy];
                     if(b[b[fy]]==0){
                     b[b[fy]]=b[fx];
                     b[b[fx]]=b[fy];
                    }
                 }
                b[fx]=fy;
                 b[fy]=fx;
                 printf("Yes\n");
            }
        }
    }
    /*
     for(i=1;i<=n;i++)
    {
         printf("%d ",father[i]);
    }
        printf("\n");
    for(i=1;i<=n;i++)
    {
         printf("%d ",b[i]);
    }
*/
    for(i=0;i<q;i++)
    {
         scanf("%s%s",str1,str2);
          int fx=Find(mp[str1]);
          int fy=Find(mp[str2]);
          if(fx==fy)
            printf("1\n");
          else if(b[fx]==fy)
                printf("2\n");
            else
               printf("3\n");
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;
const int N=1e5+10;
int father[N],b[N];
map<string,int> mp;
int Find(int x)
{
      if(father[x]!=x)
         return father[x] = Find(father[x]);
        return x;
}
int main()
{
    int n,m,q,i,d;
    char str[100],str1[100],str2[100];
    for(i=0; i<=1e5; i++)
        father[i]=i;
    cin>>n>>m>>q;
    for(i=0; i<n; i++)
    {
        scanf("%s",str);
        mp[str]=i+1;
    }
    for(i=0; i<m; i++)
    {
        scanf("%d%s%s",&d,str1,str2);
        int x=mp[str1];
        int y=mp[str2];
        int fx=Find(x);
        int fy=Find(y);
        if(d==1)
        {
            if(b[fx]!=fy)
            {
                if(fx!=fy)
                {
                    father[fy]=fx;
                    if(b[fx]==0){
                    b[fx]=b[fy];
                    b[b[fy]]=fx;}
                }
                printf("YES\n");
            }
            else
            {
                printf("NO\n");
            }
        }
        else
        {
            if(fx==fy)
            {
                printf("NO\n");
            }
            else {
                 if(b[fx]!=0&&b[fx]!=fy)
                 {
                     father[fy]=b[fx];
                     if(b[b[fx]]==0){
                     b[b[fx]]=b[fy];
                     b[b[fy]]=b[fx];
                     }
                 }
                 if(b[fy]!=0&&b[fy]!=fx)
                 {
                     father[fx]=b[fy];
                     if(b[b[fy]]==0){
                     b[b[fy]]=b[fx];
                     b[b[fx]]=b[fy];
                    }
                 }
                b[fx]=fy;
                 b[fy]=fx;
                 printf("YES\n");
            }
        }
    }
    /*
     for(i=1;i<=n;i++)
    {
         printf("%d ",father[i]);
    }
        printf("\n");
    for(i=1;i<=n;i++)
    {
         printf("%d ",b[i]);
    }
*/
    for(i=0;i<q;i++)
    {
         scanf("%s%s",str1,str2);
          int fx=Find(mp[str1]);
          int fy=Find(mp[str2]);
          if(fx==fy)
            printf("1\n");
          else if(b[fx]==fy)
                printf("2\n");
            else
               printf("3\n");
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;
const int N=1e5+10;
int father[N],b[N];
map<string,int> mp;
int Find(int x)
{
    if(father[x]!=x)
        return  Find(father[x]);
    return x;
}
int main()
{
    int n,m,q,i,d;
    char str[100],str1[100],str2[100];
    for(i=0; i<=1e5; i++)
        father[i]=i;
    cin>>n>>m>>q;
    for(i=0; i<n; i++)
    {
        scanf("%s",str);
        mp[str]=i+1;
    }
    for(i=0; i<m; i++)
    {
        scanf("%d%s%s",&d,str1,str2);
        int x=mp[str1];
        int y=mp[str2];
        int fx=Find(x);
        int fy=Find(y);
        if(d==1)
        {
            if(b[fx]!=fy)
            {
                if(fx!=fy)
                {
                    father[fy]=fx;
                    if(!b[fx])
                    {
                        b[fx]=b[fy];
                        b[b[fy]]=fx;
                    }
                }
                printf("YES\n");
            }
            else
                printf("NO\n");
        }
        else
        {
            if(fx==fy)
                printf("NO\n");
            else
            {
                if(b[fx]!=0&&b[fx]!=fy)
                {
                    father[fy]=b[fx];
                    if(!b[b[fx]])
                    {
                        b[b[fx]]=b[fy];
                        b[b[fy]]=b[fx];
                    }
                }
                if(b[fy]!=0&&b[fy]!=fx)
                {
                    father[fx]=b[fy];
                    if(!b[b[fy]])
                    {
                        b[b[fy]]=b[fx];
                        b[b[fx]]=b[fy];
                    }
                }
                if(b[fy]==0&&b[fx]==0)
                {
                    b[fx]=fy;
                    b[fy]=fx;
                }
                printf("YES\n");
            }
        }
    }
    for(i=0; i<q; i++)
    {
        scanf("%s%s",str1,str2);
        int fx=Find(mp[str1]);
        int fy=Find(mp[str2]);
        if(fx==fy)
            printf("1\n");
        else if(b[fx]==fy)
            printf("2\n");
        else
            printf("3\n");
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <vector>
#include <functional>

using namespace std;

#define LL long long int
#define INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
const int MAXN = 1e05 + 7;
#define ALPHA 26

map <string, int> mp;
int syn[MAXN], opp[MAXN];

int find(int p)
{
	if (p == 0)
		return 0;
	else
	{
		while (syn[p] != p)
			p = syn[p];
		return p;
	}
}

int main()
{
	int n, m, q;
	cin >> n >> m >> q;
	for (int i = 1; i <= n; i++)
	{
		string tmp;
		cin >> tmp;
		mp[tmp] = i;
		syn[i] = i;
	}
	for (int j = 1; j <= m; j++)
	{
		syn[0] = 0;
		int judge;
		string a, b;
		cin >> judge >> a >> b;
		int ma = mp[a];
		int mb = mp[b];
		int fa = find(ma);
		int fb = find(mb);
		int pa = find(opp[ma]);
		int pb = find(opp[mb]);
		if (judge == 1)
		{
			if ((pa == 0 || pa != fb) && ( pb == 0 || pb != fa))
			{
				cout << "YES" << endl;
				syn[fa] = mb;
				syn[pa] = pb;
			}
			else
				cout << "NO" << endl;
		}
		else	//judge == 2
		{
			if (fa != fb)
			{
				cout << "YES" << endl;
				opp[fa] = fb;
				opp[fb] = fa;
				syn[pa] = fb;
				if (pb != 0)
					syn[fa] = pb;
			}
			else
				cout << "NO" << endl;
		}
	}
	for (int k = 1; k <= q; k++)
	{
		string a, b;
		cin >> a >> b;
		int ma = mp[a];
		int mb = mp[b];
		int fa = find(ma);
		int fb = find(mb);
		int pa = find(opp[ma]);
		int pb = find(opp[mb]);
		if (fa == fb || (pa == pb && pa != 0))
			cout << 1 << endl;
		else if (fa == pb || pa == fb)
			cout << 2 << endl;
		else
			cout << 3 << endl;
	}
	return 0;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <vector>
#include <functional>

using namespace std;

#define LL long long int
#define INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
const int MAXN = 1e05 + 7;
#define ALPHA 26

map <string, int> mp;
int syn[MAXN], opp[MAXN];

int find(int p)
{
	if (p == 0)
		return 0;
	else
	{
		while (syn[p] != p)
			p = syn[p];
		return p;
	}
}

int main()
{
	int n, m, q;
	cin >> n >> m >> q;
	for (int i = 1; i <= n; i++)
	{
		string tmp;
		cin >> tmp;
		mp[tmp] = i;
		syn[i] = i;
	}
	for (int j = 1; j <= m; j++)
	{
		syn[0] = 0;
		int judge;
		string a, b;
		cin >> judge >> a >> b;
		int ma = mp[a];
		int mb = mp[b];
		int fa = find(ma);
		int fb = find(mb);
		int pa = find(opp[ma]);
		int pb = find(opp[mb]);
		if (judge == 1)
		{
			if ((pa == 0 || pa != fb) && ( pb == 0 || pb != fa))
			{
				cout << "YES" << endl;
				syn[fa] = mb;
//				syn[pa] = pb;
				if (pb != 0)
					opp[fa] = pb;
				if (pa != 0)
					opp[fb] = pa;
			}
			else
				cout << "NO" << endl;
		}
		else	//judge == 2
		{
			if (fa != fb)
			{
				cout << "YES" << endl;
				opp[fa] = find(fb);
				opp[fb] = find(fa);
				syn[pa] = fb;
				if (pb != 0)
					syn[fa] = pb;
			}
			else
				cout << "NO" << endl;
		}
	}
	for (int k = 1; k <= q; k++)
	{
		string a, b;
		cin >> a >> b;
		int ma = mp[a];
		int mb = mp[b];
		int fa = find(ma);
		int fb = find(mb);
		int pa = find(opp[ma]);
		int pb = find(opp[mb]);
		if (fa == fb || (pa == pb && pa != 0))
			cout << 1 << endl;
		else if (fa == pb || pa == fb)
			cout << 2 << endl;
		else
			cout << 3 << endl;
	}
	return 0;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <vector>
#include <functional>

using namespace std;

#define LL long long int
#define INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
const int MAXN = 1e05 + 7;
#define ALPHA 26

map <string, int> mp;
int syn[MAXN], opp[MAXN];

int find(int p)
{
	if (p == 0)
		return 0;
	else
	{
		while (syn[p] != p && syn[p] != 0)
			p = syn[p];
		return p;
	}
}

int main()
{
	int n, m, q;
	cin >> n >> m >> q;
	for (int i = 1; i <= n; i++)
	{
		string tmp;
		cin >> tmp;
		mp[tmp] = i;
		syn[i] = i;
	}
	for (int j = 1; j <= m; j++)
	{
		syn[0] = 0;
		int judge;
		string a, b;
		cin >> judge >> a >> b;
		int ma = mp[a];
		int mb = mp[b];
		int fa = find(ma);
		int fb = find(mb);
		int pa = find(opp[ma]);
		int pb = find(opp[mb]);
		if (judge == 1)
		{
			if ((pa == 0 || pa != fb) && ( pb == 0 || pb != fa))
			{
				cout << "YES" << endl;
				syn[fa] = mb;
//				syn[pa] = pb;
				if (pb != 0)
					opp[fa] = pb;
				if (pa != 0)
					opp[fb] = pa;
			}
			else
				cout << "NO" << endl;
		}
		else	//judge == 2
		{
			if (fa != fb)
			{
				cout << "YES" << endl;
				opp[fa] = find(fb);
				opp[fb] = find(fa);
				syn[pa] = fb;
				if (pb != 0)
					syn[fa] = pb;
			}
			else
				cout << "NO" << endl;
		}
	}
	for (int k = 1; k <= q; k++)
	{
		string a, b;
		cin >> a >> b;
		int ma = mp[a];
		int mb = mp[b];
		int fa = find(ma);
		int fb = find(mb);
		int pa = find(opp[ma]);
		int pb = find(opp[mb]);
		if (fa == fb || (pa == pb && pa != 0))
			cout << 1 << endl;
		else if (fa == pb || pa == fb)
			cout << 2 << endl;
		else
			cout << 3 << endl;
	}
	return 0;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <vector>
#include <functional>

using namespace std;

#define LL long long int
#define INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define MAXN 10007
#define ALPHA 26

map <string, int> mp;
int syn[MAXN], opp[MAXN];

int find(int p)
{
	if (p == 0)
		return 0;
	else
	{
		while (syn[p] != p)
			p = syn[p];
		return p;
	}
}

int main()
{
	int n, m, q;
	cin >> n >> m >> q;
	for (int i = 1; i <= n; i++)
	{
		string tmp;
		cin >> tmp;
		mp[tmp] = i;
		syn[i] = i;
	}
	for (int j = 1; j <= m; j++)
	{
		int judge;
		string a, b;
		cin >> judge >> a >> b;
		int ma = mp[a];
		int mb = mp[b];
		int fa = find(ma);
		int fb = find(mb);
		int pa = find(opp[ma]);
		int pb = find(opp[mb]);
		if (judge == 1)
		{
			if (pa != fb && pb != fa)
			{
				cout << "YES" << endl;
				syn[fa] = mb;
				syn[pa] = pb;
			}
			else
				cout << "NO" << endl;
		}
		else	//judge == 2
		{
			if (fa != fb)
			{
				cout << "YES" << endl;
				opp[fa] = fb;
				opp[fb] = fa;
				syn[pa] = fb;
				if (pb != 0)
					syn[fa] = pb;
			}
			else
				cout << "NO" << endl;
		}
	}
	for (int k = 1; k <= q; k++)
	{
		string a, b;
		cin >> a >> b;
		int ma = mp[a];
		int mb = mp[b];
		int fa = find(ma);
		int fb = find(mb);
		int pa = find(opp[ma]);
		int pb = find(opp[mb]);
		if (fa == fb)
			cout << 1 << endl;
		else if (fa == pb || pa == fb)
			cout << 2 << endl;
		else
			cout << 3 << endl;
	}
	return 0;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <vector>
#include <functional>

using namespace std;

#define LL long long int
#define INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define MAXN 10007
#define ALPHA 26

map <string, int> mp;
int syn[MAXN], opp[MAXN];

int find(int p)
{
	if (p == 0)
		return 0;
	else
	{
		while (syn[p] != p)
			p = syn[p];
		return p;
	}
}

int main()
{
	int n, m, q;
	cin >> n >> m >> q;
	for (int i = 1; i <= n; i++)
	{
		string tmp;
		cin >> tmp;
		mp[tmp] = i;
		syn[i] = i;
	}
	for (int j = 1; j <= m; j++)
	{
		int judge;
		string a, b;
		cin >> judge >> a >> b;
		int ma = mp[a];
		int mb = mp[b];
		int fa = find(ma);
		int fb = find(mb);
		int pa = find(opp[ma]);
		int pb = find(opp[mb]);
		if (judge == 1)
		{
			if (pa != fb && pb != fa)
			{
				cout << "YES" << endl;
				syn[fa] = mb;
				syn[pa] = pb;
			}
			else
				cout << "NO" << endl;
		}
		else	//judge == 2
		{
			if (fa != fb)
			{
				cout << "YES" << endl;
				opp[fa] = fb;
				opp[fb] = fa;
				syn[pa] = fb;
				if (pb != 0)
					syn[fa] = pb;
			}
			else
				cout << "NO" << endl;
		}
	}
	for (int k = 1; k <= q; k++)
	{
		string a, b;
		cin >> a >> b;
		int ma = mp[a];
		int mb = mp[b];
		int fa = find(ma);
		int fb = find(mb);
		int pa = find(opp[ma]);
		int pb = find(opp[mb]);
		if (fa == fb || pa == pb)
			cout << 1 << endl;
		else if (fa == pb || pa == fb)
			cout << 2 << endl;
		else
			cout << 3 << endl;
	}
	return 0;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <vector>
#include <functional>

using namespace std;

#define LL long long int
#define INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
const int MAXN = 1e05 + 7;
#define ALPHA 26

map <string, int> mp;
int syn[MAXN], opp[MAXN];

int find(int p)
{
	if (p == 0)
		return 0;
	else
	{
		while (syn[p] != p)
			p = syn[p];
		return p;
	}
}

int main()
{
	int n, m, q;
	cin >> n >> m >> q;
	for (int i = 1; i <= n; i++)
	{
		string tmp;
		cin >> tmp;
		mp[tmp] = i;
		syn[i] = i;
	}
	for (int j = 1; j <= m; j++)
	{
		int judge;
		string a, b;
		cin >> judge >> a >> b;
		int ma = mp[a];
		int mb = mp[b];
		int fa = find(ma);
		int fb = find(mb);
		int pa = find(opp[ma]);
		int pb = find(opp[mb]);
		if (judge == 1)
		{
			if (pa != fb && pb != fa)
			{
				cout << "YES" << endl;
				syn[fa] = mb;
				syn[pa] = pb;
			}
			else
				cout << "NO" << endl;
		}
		else	//judge == 2
		{
			if (fa != fb)
			{
				cout << "YES" << endl;
				opp[fa] = fb;
				opp[fb] = fa;
				syn[pa] = fb;
				if (pb != 0)
					syn[fa] = pb;
			}
			else
				cout << "NO" << endl;
		}
	}
	for (int k = 1; k <= q; k++)
	{
		string a, b;
		cin >> a >> b;
		int ma = mp[a];
		int mb = mp[b];
		int fa = find(ma);
		int fb = find(mb);
		int pa = find(opp[ma]);
		int pb = find(opp[mb]);
		if (fa == fb || (pa == pb && pa != 0))
			cout << 1 << endl;
		else if (fa == pb || pa == fb)
			cout << 2 << endl;
		else
			cout << 3 << endl;
	}
	return 0;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <vector>
#include <functional>

using namespace std;

#define LL long long int
#define INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
const int MAXN = 1e05 + 7;
#define ALPHA 26

map <string, int> mp;
int syn[MAXN], opp[MAXN];

int find(int p)
{
	if (p == 0)
		return 0;
	else
	{
		while (syn[p] != p)
			p = syn[p];
		return p;
	}
}

int main()
{
	int n, m, q;
	cin >> n >> m >> q;
	for (int i = 1; i <= n; i++)
	{
		string tmp;
		cin >> tmp;
		mp[tmp] = i;
		syn[i] = i;
	}
	for (int j = 1; j <= m; j++)
	{
		syn[0] = 0;
		int judge;
		string a, b;
		cin >> judge >> a >> b;
		int ma = mp[a];
		int mb = mp[b];
		int fa = find(ma);
		int fb = find(mb);
		int pa = find(opp[ma]);
		int pb = find(opp[mb]);
		if (judge == 1)
		{
			if (pa != fb && pb != fa)
			{
				cout << "YES" << endl;
				syn[fa] = mb;
				syn[pa] = pb;
			}
			else
				cout << "NO" << endl;
		}
		else	//judge == 2
		{
			if (fa != fb)
			{
				cout << "YES" << endl;
				opp[fa] = fb;
				opp[fb] = fa;
				syn[pa] = fb;
				if (pb != 0)
					syn[fa] = pb;
			}
			else
				cout << "NO" << endl;
		}
	}
	for (int k = 1; k <= q; k++)
	{
		string a, b;
		cin >> a >> b;
		int ma = mp[a];
		int mb = mp[b];
		int fa = find(ma);
		int fb = find(mb);
		int pa = find(opp[ma]);
		int pb = find(opp[mb]);
		if (fa == fb || (pa == pb && pa != 0))
			cout << 1 << endl;
		else if (fa == pb || pa == fb)
			cout << 2 << endl;
		else
			cout << 3 << endl;
	}
	return 0;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <vector>
#include <functional>

using namespace std;

#define LL long long int
#define INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
const int MAXN = 1e05 + 7;
#define ALPHA 26

map <string, int> mp;
int syn[MAXN], opp[MAXN];

int find(int p)
{
	if (p == 0)
		return 0;
	else
	{
		while (syn[p] != p)
			p = syn[p];
		return p;
	}
}

int main()
{
	int n, m, q;
	cin >> n >> m >> q;
	for (int i = 1; i <= n; i++)
	{
		string tmp;
		cin >> tmp;
		mp[tmp] = i;
		syn[i] = i;
	}
	for (int j = 1; j <= m; j++)
	{
		syn[0] = 0;
		int judge;
		string a, b;
		cin >> judge >> a >> b;
		int ma = mp[a];
		int mb = mp[b];
		int fa = find(ma);
		int fb = find(mb);
		int pa = find(opp[fa]);
		int pb = find(opp[fb]);
		if (judge == 1)
		{
			if (pa != fb)
			{
				cout << "YES" << endl;
				syn[fa] = fb;
//				syn[pa] = pb;
				if (pa != 0 && pb != 0)
					syn[pa] = pb;
				if (pb == 0)
					opp[fb] = pa;
			}
			else
				cout << "NO" << endl;
		}
		else	//judge == 2
		{
			if (fa != fb)
			{
				cout << "YES" << endl;
				if (pa != 0)
					syn[fb] = pa;
				else
					opp[fa] = fb;
				if (pb != 0)
					syn[fa] = pb;
				else
					opp[fb] = fa;
			}
			else
				cout << "NO" << endl;
		}
	}
	for (int k = 1; k <= q; k++)
	{
		string a, b;
		cin >> a >> b;
		int ma = mp[a];
		int mb = mp[b];
		int fa = find(ma);
		int fb = find(mb);
		int pa = find(opp[fa]);
		int pb = find(opp[fb]);
		if (fa == fb)
			cout << 1 << endl;
		else if (fa == pb || pa == fb)
			cout << 2 << endl;
		else
			cout << 3 << endl;
	}
	return 0;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <vector>
#include <functional>

using namespace std;

#define LL long long int
#define INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
const int MAXN = 1e05 + 7;
#define ALPHA 26

map <string, int> mp;
int syn[MAXN], opp[MAXN];

int find(int p)
{
	if (p == 0)
		return 0;
	if (syn[p] != p)
		syn[p] = find(syn[p]);
	return syn[p];
}

int main()
{
	int n, m, q;
	cin >> n >> m >> q;
	for (int i = 1; i <= n; i++)
	{
		string tmp;
		cin >> tmp;
		mp[tmp] = i;
		syn[i] = i;
	}
	for (int j = 1; j <= m; j++)
	{
		syn[0] = 0;
		int judge;
		string a, b;
		cin >> judge >> a >> b;
		int ma = mp[a];
		int mb = mp[b];
		int fa = find(ma);
		int fb = find(mb);
		int pa = find(opp[fa]);
		int pb = find(opp[fb]);
		if (judge == 1)
		{
			if (pa != fb)
			{
				cout << "YES" << endl;
				syn[fa] = fb;
//				syn[pa] = pb;
				if (pa != 0 && pb != 0)
					syn[pa] = pb;
				if (pb == 0)
					opp[fb] = pa;
			}
			else
				cout << "NO" << endl;
		}
		else	//judge == 2
		{
			if (fa != fb)
			{
				cout << "YES" << endl;
				if (pa != 0)
					syn[fb] = pa;
				else
					opp[fa] = fb;
				if (pb != 0)
					syn[fa] = pb;
				else
					opp[fb] = fa;
			}
			else
				cout << "NO" << endl;
		}
	}
	for (int k = 1; k <= q; k++)
	{
		string a, b;
		cin >> a >> b;
		int ma = mp[a];
		int mb = mp[b];
		int fa = find(ma);
		int fb = find(mb);
		int pa = find(opp[fa]);
		int pb = find(opp[fb]);
		if (fa == fb)
			cout << 1 << endl;
		else if (fa == pb || pa == fb)
			cout << 2 << endl;
		else
			cout << 3 << endl;
	}
	return 0;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <vector>
#include <functional>

using namespace std;

#define LL long long int
#define INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define MAXN 10007
#define ALPHA 26

map <string, int> mp;
int syn[MAXN], opp[MAXN];

int find(int p)
{
	if (p == 0)
		return 0;
	else
	{
		while (syn[p] != p)
			p = syn[p];
		return p;
	}
}

int main()
{
	int n, m, q;
	cin >> n >> m >> q;
	for (int i = 1; i <= n; i++)
	{
		string tmp;
		cin >> tmp;
		mp[tmp] = i;
		syn[i] = i;
	}
	for (int j = 1; j <= m; j++)
	{
		int judge;
		string a, b;
		cin >> judge >> a >> b;
		int ma = mp[a];
		int mb = mp[b];
		int fa = find(ma);
		int fb = find(mb);
		int pa = find(opp[ma]);
		int pb = find(opp[mb]);
		if (judge == 1)
		{
			if (pa != fb && pb != fa)
			{
				cout << "YES" << endl;
				syn[fa] = mb;
				syn[pa] = pb;
			}
			else
				cout << "NO" << endl;
		}
		else	//judge == 2
		{
			if (fa != fb)
			{
				cout << "YES" << endl;
				opp[fa] = fb;
				opp[fb] = fa;
				syn[pa] = fb;
				if (pb != 0)
					syn[fa] = pb;
			}
			else
				cout << "NO" << endl;
		}
	}
	for (int k = 1; k <= q; k++)
	{
		string a, b;
		cin >> a >> b;
		int ma = mp[a];
		int mb = mp[b];
		int fa = find(ma);
		int fb = find(mb);
		int pa = find(opp[ma]);
		int pb = find(opp[mb]);
		if (fa == fb || (pa == pb && pa != 0))
			cout << 1 << endl;
		else if (fa == pb || pa == fb)
			cout << 2 << endl;
		else
			cout << 3 << endl;
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#define mo 10000019
using namespace std;
inline int read(){
	char c=getchar();int p=1,ret=0;
	while((c<'0')||(c>'9')){if(c=='-')p=-1;c=getchar();}
	while((c>='0')&&(c<='9'))ret=(ret<<1)+(ret<<3)+c-'0',c=getchar();
	return ret*p;
}
int fa[mo],f[mo];
int n,m,q;
char s[25];
inline int hashit(){
	int len=strlen(s),re=0;
	for(int i=0;i<len;i++)re=(re*26+s[i]-'a')%mo;
	return re;
}
inline int find(int k){
	if(fa[k]==k)return k;
	int tmp=fa[k];
	fa[k]=find(fa[k]);
	f[k]=f[tmp]^f[k];
	return fa[k];

}
int main(){
	n=read();m=read();q=read();
	for(int i=1;i<=n;i++)scanf("%s",s);
	for(int i=0;i<mo;i++)fa[i]=i,f[i]=0;
	for(int i=1;i<=m;i++){
		int flag=read()-1;
		scanf("%s",s);
		int u=hashit();
		scanf("%s",s);
		int v=hashit();
		int U=find(u),V=find(v);
		if(U==V){
			if((f[u]^f[v]^flag)==0)puts("YES");
			else puts("NO");
		}else{
			fa[U]=V;f[U]=f[u]^f[v]^flag;
			puts("YES");
		}
	}
	while(q--){
		scanf("%s",s);
		int u=hashit();
		scanf("%s",s);
		int v=hashit();
		int U=find(u),V=find(v);
		if(U!=V)puts("3");
		else printf("%d\n",(f[u]^f[v])+1);
	}
}


#include<cstdio>
#include<cstring>
#define mo 10000019
using namespace std;
inline int read(){
	char c=getchar();int p=1,ret=0;
	while((c<'0')||(c>'9')){if(c=='-')p=-1;c=getchar();}
	while((c>='0')&&(c<='9'))ret=(ret<<1)+(ret<<3)+c-'0',c=getchar();
	return ret*p;
}
int fa[mo],f[mo];
int n,m,q,cnt,len;
char s[25];
struct trie{
	int son[26];
}t[200005];
inline int findit(int k,int now){
	if(k==len)return now;
	if(!t[now].son[s[k]-'a'])t[now].son[s[k]-'a']=++cnt;
	findit(k+1,t[now].son[s[k]-'a']);
}
inline int find(int k){
	if(fa[k]==k)return k;
	int tmp=fa[k];
	fa[k]=find(fa[k]);
	f[k]=f[tmp]^f[k];
	return fa[k];
}
int main(){
	n=read();m=read();q=read();
	for(int i=1;i<=n;i++)scanf("%s",s);
	for(int i=0;i<mo;i++)fa[i]=i,f[i]=0;
	cnt=1;
	for(int i=1;i<=m;i++){
		int flag=read()-1;
		scanf("%s",s);len=strlen(s);
		int u=findit(0,1);
		scanf("%s",s);len=strlen(s);
		int v=findit(0,1);
		int U=find(u),V=find(v);
		if(U==V){
			if((f[u]^f[v]^flag)==0)puts("YES");
			else puts("NO");
		}else{
			fa[U]=V;f[U]=f[u]^f[v]^flag;
			puts("YES");
		}
	}
	while(q--){
		scanf("%s",s);len=strlen(s);
		int u=findit(0,1);
		scanf("%s",s);len=strlen(s);
		int v=findit(0,1);
		int U=find(u),V=find(v);
		if(U!=V)puts("3");
		else printf("%d\n",(f[u]^f[v])+1);
	}
}


#include<cstdio>
#include<cstring>
#define mo 10000007
using namespace std;
inline int read(){
	char c=getchar();int p=1,ret=0;
	while((c<'0')||(c>'9')){if(c=='-')p=-1;c=getchar();}
	while((c>='0')&&(c<='9'))ret=(ret<<1)+(ret<<3)+c-'0',c=getchar();
	return ret*p;
}
int fa[mo],f[mo];
int n,m,q;
char s[25];
inline int hashit(){
	int len=strlen(s),re=0;
	for(int i=0;i<len;i++)re=(re*26+s[i]-'a')%mo;
	return re;
}
inline int find(int k){
	if(fa[k]==k)return k;
	int tmp=fa[k];
	fa[k]=find(fa[k]);
	f[k]=f[tmp]^f[k];
	return fa[k];

}
int main(){
	n=read();m=read();q=read();
	for(int i=1;i<=n;i++)scanf("%s",s);
	for(int i=0;i<mo;i++)fa[i]=i,f[i]=0;
	for(int i=1;i<=m;i++){
		int flag=read()-1;
		scanf("%s",s);
		int u=hashit();
		scanf("%s",s);
		int v=hashit();
		int U=find(u),V=find(v);
		if(U==V){
			if((f[u]^f[v]^flag)==0)puts("YES");
			else puts("NO");
		}else{
			fa[U]=V;f[U]=f[u]^f[v]^flag;
			puts("YES");
		}
	}
	while(q--){
		scanf("%s",s);
		int u=hashit();
		scanf("%s",s);
		int v=hashit();
		int U=find(u),V=find(v);
		if(U!=V)puts("3");
		else printf("%d\n",(f[u]^f[v])+1);
	}
}


#include<cstdio>
#include<cstring>
#define mo 10000019
using namespace std;
inline int read(){
	char c=getchar();int p=1,ret=0;
	while((c<'0')||(c>'9')){if(c=='-')p=-1;c=getchar();}
	while((c>='0')&&(c<='9'))ret=(ret<<1)+(ret<<3)+c-'0',c=getchar();
	return ret*p;
}
int fa[mo],f[mo];
int n,m,q,cnt,len;
char s[25];
struct trie{
	int son[26];
}t[5000005];
inline int findit(int k,int now){
	if(k==len)return now;
	if(!t[now].son[s[k]-'a'])t[now].son[s[k]-'a']=++cnt;
	findit(k+1,t[now].son[s[k]-'a']);
}
inline int find(int k){
	if(fa[k]==k)return k;
	int tmp=fa[k];
	fa[k]=find(fa[k]);
	f[k]=f[tmp]^f[k];
	return fa[k];
}
int main(){
	n=read();m=read();q=read();
	for(int i=1;i<=n;i++)scanf("%s",s);
	for(int i=0;i<mo;i++)fa[i]=i,f[i]=0;
	cnt=1;
	for(int i=1;i<=m;i++){
		int flag=read()-1;
		scanf("%s",s);len=strlen(s);
		int u=findit(0,1);
		scanf("%s",s);len=strlen(s);
		int v=findit(0,1);
		int U=find(u),V=find(v);
		if(U==V){
			if((f[u]^f[v]^flag)==0)puts("YES");
			else puts("NO");
		}else{
			fa[U]=V;f[U]=f[u]^f[v]^flag;
			puts("YES");
		}
	}
	while(q--){
		scanf("%s",s);len=strlen(s);
		int u=findit(0,1);
		scanf("%s",s);len=strlen(s);
		int v=findit(0,1);
		int U=find(u),V=find(v);
		if(U!=V)puts("3");
		else printf("%d\n",(f[u]^f[v])+1);
	}
}


#include<cstdio>
#include<cstring>
#define mo 10000019
using namespace std;
inline int read(){
	char c=getchar();int p=1,ret=0;
	while((c<'0')||(c>'9')){if(c=='-')p=-1;c=getchar();}
	while((c>='0')&&(c<='9'))ret=(ret<<1)+(ret<<3)+c-'0',c=getchar();
	return ret*p;
}
int fa[mo],f[mo];
int n,m,q,cnt,len;
char s[25];
struct trie{
	int son[26];
}t[3000005];
inline int findit(int k,int now){
	if(k==len)return now;
	if(!t[now].son[s[k]-'a'])t[now].son[s[k]-'a']=++cnt;
	findit(k+1,t[now].son[s[k]-'a']);
}
inline int find(int k){
	if(fa[k]==k)return k;
	int tmp=fa[k];
	fa[k]=find(fa[k]);
	f[k]=f[tmp]^f[k];
	return fa[k];
}
int main(){
	n=read();m=read();q=read();
	for(int i=1;i<=n;i++)scanf("%s",s);
	for(int i=0;i<mo;i++)fa[i]=i,f[i]=0;
	cnt=1;
	for(int i=1;i<=m;i++){
		int flag=read()-1;
		scanf("%s",s);len=strlen(s);
		int u=findit(0,1);
		scanf("%s",s);len=strlen(s);
		int v=findit(0,1);
		int U=find(u),V=find(v);
		if(U==V){
			if((f[u]^f[v]^flag)==0)puts("YES");
			else puts("NO");
		}else{
			fa[U]=V;f[U]=f[u]^f[v]^flag;
			puts("YES");
		}
	}
	while(q--){
		scanf("%s",s);len=strlen(s);
		int u=findit(0,1);
		scanf("%s",s);len=strlen(s);
		int v=findit(0,1);
		int U=find(u),V=find(v);
		if(U!=V)puts("3");
		else printf("%d\n",(f[u]^f[v])+1);
	}
}


#include<cstdio>
#include<cstring>
using namespace std;
inline int read(){
	char c=getchar();int p=1,ret=0;
	while((c<'0')||(c>'9')){if(c=='-')p=-1;c=getchar();}
	while((c>='0')&&(c<='9'))ret=(ret<<1)+(ret<<3)+c-'0',c=getchar();
	return ret*p;
}
int fa[2000005],f[2000005];
int n,m,q,cnt,len;
char s[25];
struct trie{
	int son[26];
}t[2000005];
inline int findit(int k,int now){
	if(k==len)return now;
	if(!t[now].son[s[k]-'a'])t[now].son[s[k]-'a']=++cnt,fa[cnt]=cnt,f[cnt]=0;
	return findit(k+1,t[now].son[s[k]-'a']);
}
inline int find(int k){
	if(fa[k]==k)return k;
	int tmp=fa[k];
	fa[k]=find(fa[k]);
	f[k]=f[tmp]^f[k];
	return fa[k];
}
int main(){
	n=read();m=read();q=read();
	for(int i=1;i<=n;i++)scanf("%s",s);
	cnt=1;
	for(int i=1;i<=m;i++){
		int flag=read()-1;
		scanf("%s",s);len=strlen(s);
		int u=findit(0,1);
		scanf("%s",s);len=strlen(s);
		int v=findit(0,1);
		int U=find(u),V=find(v);
		if(U==V){
			if((f[u]^f[v]^flag)==0)puts("YES");
			else puts("NO");
		}else{
			fa[U]=V;f[U]=f[u]^f[v]^flag;
			puts("YES");
		}
	}
	while(q--){
		scanf("%s",s);len=strlen(s);
		int u=findit(0,1);
		scanf("%s",s);len=strlen(s);
		int v=findit(0,1);
		int U=find(u),V=find(v);
		if(U!=V)puts("3");
		else printf("%d\n",(f[u]^f[v])+1);
	}
}


#include<cstdio>
#include<cstring>
using namespace std;
inline int read(){
	char c=getchar();int p=1,ret=0;
	while((c<'0')||(c>'9')){if(c=='-')p=-1;c=getchar();}
	while((c>='0')&&(c<='9'))ret=(ret<<1)+(ret<<3)+c-'0',c=getchar();
	return ret*p;
}
int fa[3000005],f[3000005];
int n,m,q,cnt,len;
char s[25];
struct trie{
	int son[26];
}t[3000005];
inline int findit(int k,int now){
	if(k==len)return now;
	if(!t[now].son[s[k]-'a'])t[now].son[s[k]-'a']=++cnt,fa[cnt]=cnt,f[cnt]=0;
	return findit(k+1,t[now].son[s[k]-'a']);
}
inline int find(int k){
	if(fa[k]==k)return k;
	int tmp=fa[k];
	fa[k]=find(fa[k]);
	f[k]=f[tmp]^f[k];
	return fa[k];
}
int main(){
	n=read();m=read();q=read();
	for(int i=1;i<=n;i++)scanf("%s",s);
	cnt=1;
	for(int i=1;i<=m;i++){
		int flag=read()-1;
		scanf("%s",s);len=strlen(s);
		int u=findit(0,1);
		scanf("%s",s);len=strlen(s);
		int v=findit(0,1);
		int U=find(u),V=find(v);
		if(U==V){
			if((f[u]^f[v]^flag)==0)puts("YES");
			else puts("NO");
		}else{
			fa[U]=V;f[U]=f[u]^f[v]^flag;
			puts("YES");
		}
	}
	while(q--){
		scanf("%s",s);len=strlen(s);
		int u=findit(0,1);
		scanf("%s",s);len=strlen(s);
		int v=findit(0,1);
		int U=find(u),V=find(v);
		if(U!=V)puts("3");
		else printf("%d\n",(f[u]^f[v])+1);
	}
}


#include<cstdio>
#include<cstring>
using namespace std;
inline int read(){
	char c=getchar();int p=1,ret=0;
	while((c<'0')||(c>'9')){if(c=='-')p=-1;c=getchar();}
	while((c>='0')&&(c<='9'))ret=(ret<<1)+(ret<<3)+c-'0',c=getchar();
	return ret*p;
}
int n,m,q,cnt,len;
char s[25];
struct trie{
	int son[26];
}t[3000005];
inline int findit(int k,int now){
	if(k==len)return now;
	if(!t[now].son[s[k]-'a'])t[now].son[s[k]-'a']=++cnt;
	findit(k+1,t[now].son[s[k]-'a']);
}
inline int find(int k){
	if(fa[k]==k)return k;
	int tmp=fa[k];
	fa[k]=find(fa[k]);
	f[k]=f[tmp]^f[k];
	return fa[k];
}
int main(){
	n=read();m=read();q=read();
	for(int i=1;i<=n;i++)scanf("%s",s);
	for(int i=0;i<mo;i++)fa[i]=i,f[i]=0;
	cnt=1;
	for(int i=1;i<=m;i++){
		int flag=read()-1;
		scanf("%s",s);len=strlen(s);
		int u=findit(0,1);
		scanf("%s",s);len=strlen(s);
		int v=findit(0,1);
		int U=find(u),V=find(v);
		if(U==V){
			if((f[u]^f[v]^flag)==0)puts("YES");
			else puts("NO");
		}else{
			fa[U]=V;f[U]=f[u]^f[v]^flag;
			puts("YES");
		}
	}
	while(q--){
		scanf("%s",s);len=strlen(s);
		int u=findit(0,1);
		scanf("%s",s);len=strlen(s);
		int v=findit(0,1);
		int U=find(u),V=find(v);
		if(U!=V)puts("3");
		else printf("%d\n",(f[u]^f[v])+1);
	}
}


#include<iostream>
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<string>
#include<map>
#define maxn 100005
using namespace std;
inline int read()
{
	int x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
map<string,int> Map;
int fa[maxn<<1];
int find(int x)
{
	return fa[x]==x ? x : fa[x]=find(fa[x]);
}
bool same(int x,int y)
{
	return find(x)==find(y);
}
void Union(int x,int y)
{
	x=find(x),y=find(y);
	if(x==y) return;
	fa[x]=y;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n,m,q;
	cin>>n>>m>>q;
	for(int i=1;i<=n<<1;i++) fa[i]=i;
	string s,t;
	for(int i=1;i<=n;i++)
	{
		cin>>s;
		Map[s]=i;
	}
	while(m--)
	{
		int cmd;
		cin>>cmd>>s>>t;
		int x=Map[s],y=Map[t];
		if(cmd==1)
		{
			if(same(x,y+n)) puts("NO");
			else puts("YES"),Union(x,y),Union(x+n,y+n);
		}
		else
		{
			if(same(x,y)) puts("NO");
			else puts("YES"),Union(x+n,y),Union(x,y+n);
		}
	}
	while(q--)
	{
		cin>>s>>t;
		int x=Map[s],y=Map[t];
		if(same(x,y)) puts("1");
		else if(same(x,y+n)) puts("2");
		else puts("3");
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<string>
#include<map>
#define maxn 100005
using namespace std;
inline int read()
{
	int x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
map<string,int> Map;
int fa[maxn<<1];
int find(int x)
{
	return fa[x]==x ? x : fa[x]=find(fa[x]);
}
bool same(int x,int y)
{
	return find(x)==find(y);
}
void Union(int x,int y)
{
	x=find(x),y=find(y);
	if(x==y) return;
	fa[x]=y;
}
int main()
{
	ios::sync_with_stdio(false);
	int n,m,q;
	cin>>n>>m>>q;
	for(int i=1;i<=n<<1;i++) fa[i]=i;
	string s,t;
	for(int i=1;i<=n;i++)
	{
		cin>>s;
		Map[s]=i;
	}
	while(m--)
	{
		int cmd;
		cin>>cmd>>s>>t;
		int x=Map[s],y=Map[t];
		if(cmd==1)
		{
			if(same(x,y+n)) puts("NO");
			else puts("YES"),Union(x,y),Union(x+n,y+n);
		}
		else
		{
			if(same(x,y)) puts("NO");
			else puts("YES"),Union(x+n,y),Union(x,y+n);
		}
	}
	while(q--)
	{
		cin>>s>>t;
		int x=Map[s],y=Map[t];
		if(same(x,y)) puts("1");
		else if(same(x,y+n)) puts("2");
		else puts("3");
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<string>
#include<map>
#define maxn 100005
using namespace std;
inline int read()
{
	int x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
map<string,int> Map;
int fa[maxn<<1];
int find(int x)
{
	return fa[x]==x ? x : fa[x]=find(fa[x]);
}
bool same(int x,int y)
{
	return find(x)==find(y);
}
void Union(int x,int y)
{
	x=find(x),y=find(y);
	if(x==y) return;
	fa[x]=y;
}
int main()
{
	char s[25],t[25];
	int n=read(),m=read(),q=read();
	for(int i=1;i<=n<<1;i++) fa[i]=i;
	for(int i=1;i<=n;i++)
	{
		scanf("%s",s);
		Map[s]=i;
	}
	while(m--)
	{
		int cmd=read();
		scanf("%s%s",s,t);
		int x=Map[s],y=Map[t];
		if(cmd==1)
		{
			if(same(x,y+n)) puts("NO");
			else puts("YES"),Union(x,y),Union(x+n,y+n);
		}
		else
		{
			if(same(x,y)) puts("NO");
			else puts("YES"),Union(x+n,y),Union(x,y+n);
		}
	}
	while(q--)
	{
		scanf("%s %s",s,t);
		int x=Map[s],y=Map[t];
		if(same(x,y)) puts("1");
		else if(same(x,y+n)) puts("2");
		else puts("3");
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<string>
#include<map>
#define maxn 100005
using namespace std;
inline int read()
{
	int x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
map<string,int> Map;
int fa[maxn<<1];
int find(int x)
{
	return fa[x]==x ? x : fa[x]=find(fa[x]);
}
bool same(int x,int y)
{
	return find(x)==find(y);
}
void Union(int x,int y)
{
	x=find(x),y=find(y);
	if(x==y) return;
	fa[x]=y;
}
int main()
{
	int n=read(),m=read(),q=read();
	ios::sync_with_stdio(false);
	for(int i=1;i<=n<<1;i++) fa[i]=i;
	string s,t;
	for(int i=1;i<=n;i++)
	{
		cin>>s;
		Map[s]=i;
	}
	while(m--)
	{
		int cmd;
		cin>>cmd>>s>>t;
		int x=Map[s],y=Map[t];
		if(cmd==1)
		{
			if(same(x,y+n)) puts("NO");
			else puts("YES"),Union(x,y),Union(x+n,y+n);
		}
		else
		{
			if(same(x,y)) puts("NO");
			else puts("YES"),Union(x+n,y),Union(x,y+n);
		}
	}
	while(q--)
	{
		cin>>s>>t;
		int x=Map[s],y=Map[t];
		if(same(x,y)) puts("1");
		else if(same(x,y+n)) puts("2");
		else puts("3");
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<string>
#include<map>
#define maxn 100005
using namespace std;
inline int read()
{
	int x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
map<string,int> Map;
int fa[maxn<<1];
int find(int x)
{
	return fa[x]==x ? x : fa[x]=find(fa[x]);
}
bool same(int x,int y)
{
	return find(x)==find(y);
}
void Union(int x,int y)
{
	x=find(x),y=find(y);
	if(x==y) return;
	fa[x]=y;
}
int main()
{
	ios::sync_with_stdio(false);
	int n=read(),m=read(),q=read();
	for(int i=1;i<=n<<1;i++) fa[i]=i;
	string s,t;
	for(int i=1;i<=n;i++)
	{
		cin>>s;
		Map[s]=i;
	}
	while(m--)
	{
		int cmd;
		cin>>cmd>>s>>t;
		int x=Map[s],y=Map[t];
		if(cmd==1)
		{
			if(same(x,y+n)) puts("NO");
			else puts("YES"),Union(x,y),Union(x+n,y+n);
		}
		else
		{
			if(same(x,y)) puts("NO");
			else puts("YES"),Union(x+n,y),Union(x,y+n);
		}
	}
	while(q--)
	{
		cin>>s>>t;
		int x=Map[s],y=Map[t];
		if(same(x,y)) puts("1");
		else if(same(x,y+n)) puts("2");
		else puts("3");
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<string>
#include<map>
#define maxn 100005
using namespace std;
inline int read()
{
	int x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
map<string,int> Map;
int fa[maxn<<1];
int find(int x)
{
	return fa[x]==x ? x : fa[x]=find(fa[x]);
}
bool same(int x,int y)
{
	return find(x)==find(y);
}
void Union(int x,int y)
{
	x=find(x),y=find(y);
	if(x==y) return;
	fa[x]=y;
}
int main()
{
	int n=read(),m=read(),q=read();
	for(int i=1;i<=n<<1;i++) fa[i]=i;
	for(int i=1;i<=n;i++)
	{
		string s;
		s.resize(25);
		scanf("%s",&s[0]);
		Map[s]=i;
	}
	while(m--)
	{
		int cmd=read();
		string s,t;
		s.resize(25);
		t.resize(25);
		scanf("%s%s",&s[0],&t[0]);
		int x=Map[s],y=Map[t];
		if(cmd==1)
		{
			if(same(x,y+n)) puts("NO");
			else puts("YES"),Union(x,y),Union(x+n,y+n);
		}
		else
		{
			if(same(x,y)) puts("NO");
			else puts("YES"),Union(x+n,y),Union(x,y+n);
		}
	}
	while(q--)
	{
		string s,t;
		s.resize(25);
		t.resize(25);
		scanf("%s %s",&s[0],&t[0]);
		int x=Map[s],y=Map[t];
		if(same(x,y)) puts("1");
		else if(same(x,y+n)) puts("2");
		else puts("3");
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<string>
#include<map>
#define maxn 100005
using namespace std;
inline int read()
{
	int x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
map<string,int> Map;
int fa[maxn<<1];
int find(int x)
{
	return fa[x]==x ? x : fa[x]=find(fa[x]);
}
bool same(int x,int y)
{
	return find(x)==find(y);
}
void Union(int x,int y)
{
	x=find(x),y=find(y);
	if(x==y) return;
	fa[x]=y;
}
int main()
{
	int n=read(),m=read(),q=read();
	for(int i=1;i<=n<<1;i++) fa[i]=i;
	for(int i=1;i<=n;i++)
	{
		string s;
		s.resize(25);
		scanf("%s",&s[0]);
		Map[s]=i;
	}
	while(m--)
	{
		int cmd=read();
		string s,t;
		s.resize(25);
		t.resize(25);
		scanf("%s%s",&s[0],&t[0]);
		int x=Map[s],y=Map[t];
		printf("%d %d\n",x,y);
		if(cmd==1)
		{
			if(same(x,y+n)) puts("NO");
			else puts("YES"),Union(x,y),Union(x+n,y+n);
		}
		else
		{
			if(same(x,y)) puts("NO");
			else puts("YES"),Union(x+n,y),Union(x,y+n);
		}
	}
	while(q--)
	{
		string s,t;
		s.resize(25);
		t.resize(25);
		scanf("%s %s",&s[0],&t[0]);
		int x=Map[s],y=Map[t];
		if(same(x,y)) puts("1");
		else if(same(x,y+n)) puts("2");
		else puts("3");
	}
	return 0;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define pb pop_back
#define siz(a) int(a.size())
//for traversing the container (bcoz we cannot access linked list etc with direct index)
//c stands for container and it for iterator
#define tr(c, it) \
		for(typeof(c.begin()) it=c.begin() ; it != c.end() ; it++)

#define all(c) c.begin(), c.end()
#define present(container, element) (container.find(element) != container.end()) //whether the element is present in the container

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
#define scan(x) scanf("%lld", &x)
#define print(x) printf("%lld", x)
#define pN printf("\n");
using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef vector < ll > vll;
typedef vector < vll > vvll;

typedef pair < int , int > ii;

const int mod=1e9+7;
const int maxn=2e5+50;

ll arr[maxn], n;

ll find(ll root){

	while(root != arr[root]){
		arr[root] = arr[arr[root]];
		root = arr[root];
	}
	return root;
}

ll join(ll root1,ll root2, ll type){

	ll loveA = find(root1);
	ll loveB = find(root2);
	ll hateA = find(root1+n);
	ll hateB = find(root2+n);

	if(type == 1){
		if(loveA == hateB)
			return 0;

		if(loveA != loveB)
			arr[loveA] = loveB;
		if(hateA != hateB)
			arr[hateA] = hateB;

		return 1;
	} else{

		if(loveA == loveB )
			return 0;

		if(loveA != hateB)
			arr[loveA] = hateB;

		if(hateA != loveB)
			arr[hateA] = loveB;

		return 1;
	}

}
map<string, int > mp;
int main()
{
	ios_base::sync_with_stdio(0);

	ll m, q, ch, check, root1, root2, i;

	cin >> n >> m >> q;

	string str, str1, str2;

	//inititialize(n);

	for(i=1; i<=n; i++)
	{
		cin >> str;

		mp[str]=i;

		arr[i]=i;
		arr[i+n]=i+n;
	}
	//map<string, ll> :: iterator it=mp.begin();
	while(m--){
		cin >> ch >> str1 >> str2;
		root1 = mp[str1];
		root2 = mp[str2];

		check=join(root1, root2, ch);

		//trace3(check, root1, root2);

		if(check==1)
			cout << "YES\n";
		else
			cout << "NO\n";

	//	for(i=1; i<=n; i++)
			//trace3(i, hate[i], love[i]);
	}

	while(q--) {
		cin >> str1 >> str2;

		root1 = mp[str1];
		root2 = mp[str2];

		//root1L = find_love(root1);
		//root2L = find_love(root2);

		if(	find(root1) == find(root2) )
			cout << "1\n";
		else {

			if( find(root1)  == find(root2+n) )
				cout << "2\n";
			else
				cout << "3\n";
		}
	}

	return 0;
}

/*
ll hate[maxn], love[maxn], sizeL[maxn], sizeH[maxn];

void inititialize(ll n){

	for(ll i=0; i<=n ;i++){
		sizeL[i]=1;
		sizeH[i]=1;
		love[i]=i;
		hate[i]=-1;
	}
	return ;
}

ll find_hate(ll root)
{
	while(root != hate[root])
	{
		root = hate[root];
	}

	return root;
}

ll find_love(ll root)
{
	while(root != love[root])
	{
		root = love[root];
	}
	return root;
}

ll union_love(ll rootA, ll rootB){
	ll root1 = find_love(rootA);
	ll root2 = find_love(rootB);

	if(root1==root2)
		return 1;

	ll croot1 = find_hate(root1);
	ll croot2 = find_hate(root2);

	trace3(rootA, root1, croot1);
	trace3(rootB, root2, croot2);
	if(croot1 == croot2)
		return -1;

	if(sizeL[root1] > sizeL[root2]){
		love[root2] = love[root1];

		sizeL[root1] += sizeL[root2];

	} else {
		love[root1] = love[root2];

		sizeL[root2] += sizeL[root1];
	}

	hate[croot1] = hate[croot2];

	return 1;
}

ll union_hate(ll rootA, ll rootB)
{

	ll croot1 = find_love(rootA);
	ll croot2 = find_love(rootB);

	ll root1 = find_hate(croot1);
	ll root2 = find_hate(croot2);

	if(root1==root2)
		return 1;

	trace3(rootA, root1, croot1);
	trace3(rootB, root2, croot2);
	if(croot1 == croot2)
		return -1;

	if(sizeH[croot1] > sizeH[croot2]){
		hate[croot2] = hate[croot1];

		sizeH[croot1] += sizeH[croot2];
	} else {
		hate[croot1] = hate[croot2];

		sizeH[croot2] += sizeH[croot1];
	}

	return 1;

}
*/