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

#define fastio          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define sze             200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define pr(x);          for(auto el : x) cout<<el<<' '; cout<<'\n';
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define mxel            max_element
#define mnel            min_element
#define db(...)         debug(#__VA_ARGS__, __VA_ARGS__)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename Arg1> void debug(const char* name, Arg1&& arg1){cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void debug(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " = " << arg1;
    debug(comma, args...);
}

void c_p_c()
{
    fastio;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("output.txt", "w", stderr);
    #endif
}

int arr[10001]={};

int32_t main()
{
    c_p_c();

    int n,m; cin>>n>>m;

    mii cnt;
    vector<pii> notsrt;

    while(m--)
    {
        int t,l,r; cin>>t>>l>>r;

        if(!t)
            notsrt.pb(mp(l,r));

        else
        {
            if(cnt.empty())
                cnt[l]=r;

            auto it = cnt.upper_bound(l);

            if(it==cnt.begin())
            {
                cnt[l]=r;
                it = cnt.upper_bound(r);
                it--;
                while(it->ff!=l)
                {
                    int end = it->ss;
                    cnt.erase(it);
                    cnt[l] = max(cnt[l],end);
                    r=cnt[l];

                    it = cnt.upper_bound(r);
                    it--;
                }
            }
            else
            {
                it--;
                int st;
                if(it->ss >= l)
                {
                    it->ss = max(r,it->ss);
                    r = it->ss;
                    st = it->ff;
                }
                else
                {
                    cnt[l]=r;
                    st = l;
                }

                it = cnt.upper_bound(r);
                it--;
                while(it->ff!=st)
                {
                    int end = it->ss;
                    cnt.erase(it);
                    cnt[st] = max(cnt[st],end);
                    r = cnt[st];

                    it = cnt.upper_bound(r);
                    it--;
                }
            }
        }
    }

    int val = 1000000000;
    auto it = cnt.begin();

    while(it!=cnt.end())
    {
        //cout<<it->ff<<' '<<it->ss<<'\n';
        auto tmp = it;
        tmp++;

        for(int id=it->ff;id<=it->ss;++id)
            arr[id]=val;

        if(tmp!=cnt.end())
        {
            val -= (tmp->ff-it->ss+1);
        }
        it=tmp;
    }

    for(int i=1;i<=n;++i)
        if(!arr[i])
        {
            if(i==1)
                arr[i]=1000000000;
            else
                arr[i]=arr[i-1]-1;
        }

    for(auto el : notsrt)
    {
        bool found=0;

        for(int i=el.ff;i<el.ss;++i)
        {
            if(arr[i+1]<arr[i])
            {
                found=1;
                break;
            }
        }

        if(!found)
        {
            cout<<"NO\n";
            return 0;
        }
    }

    cout<<"YES\n";

    for(int i=1;i<=n;++i)
        cout<<arr[i]<<" ";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
# define ll  long long  int
# define ld  long double
# define pb push_back
# define pp pop_back
# define ff first
# define ss second
# define mp make_pair
# define ac accumulate
# define mod 1000000007
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll power(ll x, ll y, ll p)
{
    ll res = 1;

    x = x % p;

    while (y > 0)
    {

        if (y & 1)
            res = (res*x) % p;

        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
bool sortinrev(const pair<ll,ll> &a,
               const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
typedef pair<int,int> ii;
// bool cmp(ii a,ii b)
// {
// 	if(a.ff==b.ff)
// 	{
// 		return a.ss>b.ss;
// 	}
// 	else
// 		a.ff<b.ff;
// }
   ll dp[27][200004]={0};
   bool visit[100000]={0};
int  main()
{
   #ifndef ONLINE_JUDGE
   freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
   #endif
   IOS;
   ll n,m;
   cin>>n>>m;
   vector<pair<ll,ll>>brr,crr,drr,err;
   for(ll i=0;i<m;i++)
   {
   		ll a,b,c;
   		cin>>a>>b>>c;
   		if(a==1)
   		{
   			brr.pb(mp(b,c));
   		}
   		else
   			crr.pb(mp(b,c));
   }

ll a,b;
  if(brr.size()!=0)
  {
  	sort(brr.begin(),brr.end());
  		 ll a=brr[0].ff,b=brr[0].ss;
	   for(ll i=0;i<brr.size();i++)
	   {
	   		ll flag=0;
	   		for(ll j=i;j<brr.size();j++)
	   		{
	   			if(brr[j].ff>b)
	   			{
	   				flag=-1;
	   				drr.pb(mp(a,b));
	   				a=brr[j].ff;
	   				b=brr[j].ss;
	   				i=j-1;
	   				break;
	   			}
	   			b=max(b,brr[j].ss);
	   		}
	   		if(flag==0)
	   		{
	   			drr.pb(mp(a,b));
	   			break;
	   		}
	   }
  }

      if(crr.size()!=0)
   {
		    sort(crr.begin(),crr.end());
		   a=crr[0].ff;b=crr[0].ss;
		    for(ll i=0;i<crr.size();i++)
		   {
		   		ll flag=0;
		   		for(ll j=i;j<crr.size();j++)
		   		{
		   			if(crr[j].ff>=b)
		   			{
		   				flag=-1;
		   				err.pb(mp(a,b));
		   				a=crr[j].ff;
		   				b=crr[j].ss;
		   				i=j-1;
		   				break;
		   			}
		   			b=max(b,crr[j].ss);
		   		}
		   		if(flag==0)
		   		{
		   			err.pb(mp(a,b));
		   			break;
		   		}
		   }
	}
    ll cnt=0;
		   for(ll i=0;i<drr.size();i++)
		   {
		   		for(ll j=0;j<crr.size();j++)
		   		{
		   			if(crr[j].ff>=drr[i].ff && crr[j].ss<=drr[i].ss)
		   			{
		   				cout<<"NO\n";
		   				return 0;
		   			}
		   		}
		   }
    cnt=6000002;
   ll ans[n+2];
   for(ll i=0;i<drr.size();i++)
   {
   //	cout<<drr[i].ff<<" "<<drr[i].ss<<endl;
   		for(ll j=drr[i].ff;j<=drr[i].ss;j++)
   		{
   			visit[j]=true;
   			ans[j]=cnt;
   			//cout<<j<<" "<<ans[j]<<endl;
   		}
   		cnt-=2;
   }
  for(ll i=0;i<drr.size()-1;i++)
  {
  	ll k=ans[drr[i].ss];
  		for(ll j=drr[i].ss+1;j<drr[i+1].ff;j++)
  		{
  			ans[j]=ans[j-1]-1;
  		}
  }
  for(ll j=drr[drr.size()-1].ss+1;j<=n;j++)
  {
  		ans[j]=ans[j-1]-1;
  }
   for(ll i=1;i<=n;i++)
   	if(visit[i]==0)
   		ans[i]=10000000;
   	cout<<"YES\n";
   	for(ll i=1;i<=n;i++)
   		cout<<ans[i]<<" ";

}


#include <bits/stdc++.h>
using namespace std;
# define ll  long long  int
# define ld  long double
# define pb push_back
# define pp pop_back
# define ff first
# define ss second
# define mp make_pair
# define ac accumulate
# define mod 1000000007
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll power(ll x, ll y, ll p)
{
    ll res = 1;

    x = x % p;

    while (y > 0)
    {

        if (y & 1)
            res = (res*x) % p;

        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
bool sortinrev(const pair<ll,ll> &a,
               const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
typedef pair<int,int> ii;
// bool cmp(ii a,ii b)
// {
// 	if(a.ff==b.ff)
// 	{
// 		return a.ss>b.ss;
// 	}
// 	else
// 		a.ff<b.ff;
// }
   ll dp[27][200004]={0};
   bool visit[100000]={0};
int  main()
{
   #ifndef ONLINE_JUDGE
   freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
   #endif
   IOS;
   ll n,m;
   cin>>n>>m;
   vector<pair<ll,ll>>brr,crr,drr,err;
   for(ll i=0;i<m;i++)
   {
   		ll a,b,c;
   		cin>>a>>b>>c;
   		if(a==1)
   		{
   			brr.pb(mp(b,c));
   		}
   		else
   			crr.pb(mp(b,c));
   }

ll a,b;
  if(brr.size()!=0)
  {
  	sort(brr.begin(),brr.end());
  		 ll a=brr[0].ff,b=brr[0].ss;
	   for(ll i=0;i<brr.size();i++)
	   {
	   		ll flag=0;
	   		for(ll j=i;j<brr.size();j++)
	   		{
	   			if(brr[j].ff>b)
	   			{
	   				flag=-1;
	   				drr.pb(mp(a,b));
	   				a=brr[j].ff;
	   				b=brr[j].ss;
	   				i=j-1;
	   				break;
	   			}
	   			b=max(b,brr[j].ss);
	   		}
	   		if(flag==0)
	   		{
	   			drr.pb(mp(a,b));
	   			break;
	   		}
	   }
  }

      if(crr.size()!=0)
   {
		    sort(crr.begin(),crr.end());
		   a=crr[0].ff;b=crr[0].ss;
		    for(ll i=0;i<crr.size();i++)
		   {
		   		ll flag=0;
		   		for(ll j=i;j<crr.size();j++)
		   		{
		   			if(crr[j].ff>=b)
		   			{
		   				flag=-1;
		   				err.pb(mp(a,b));
		   				a=crr[j].ff;
		   				b=crr[j].ss;
		   				i=j-1;
		   				break;
		   			}
		   			b=max(b,crr[j].ss);
		   		}
		   		if(flag==0)
		   		{
		   			err.pb(mp(a,b));
		   			break;
		   		}
		   }
	}
    ll cnt=0;
		   for(ll i=0;i<drr.size();i++)
		   {
		   		for(ll j=0;j<crr.size();j++)
		   		{
		   			if(crr[j].ff>=drr[i].ff && crr[j].ss<=drr[i].ss)
		   			{
		   				cout<<"NO\n";
		   				return 0;
		   			}
		   		}
		   }
    cnt=6000002;
   ll ans[n+2];
   for(ll i=0;i<drr.size();i++)
   {
   //	cout<<drr[i].ff<<" "<<drr[i].ss<<endl;
   		for(ll j=drr[i].ff;j<=drr[i].ss;j++)
   		{
   			visit[j]=true;
   			ans[j]=cnt;
   			//cout<<j<<" "<<ans[j]<<endl;
   		}
   		cnt-=2;
   }
  for(ll i=0;i<drr.size()-1;i++)
  {
  	ll k=ans[drr[i].ss];
  		for(ll j=drr[i].ss+1;j<drr[i+1].ff;j++)
  		{
  			ans[j]=ans[j-1]-1;
  			visit[j]=true;
  		}
  }
  for(ll j=drr[drr.size()-1].ss+1;j<=n;j++)
  {
  		ans[j]=ans[j-1]-1;
  		visit[j]=true;
  }
   for(ll i=1;i<=n;i++)
   	if(visit[i]==0)
   		ans[i]=1e7-i;
   	cout<<"YES\n";
   	for(ll i=1;i<=n;i++)
   		cout<<ans[i]<<" ";

}


#include <bits/stdc++.h>
using namespace std;
# define ll  long long  int
# define ld  long double
# define pb push_back
# define pp pop_back
# define ff first
# define ss second
# define mp make_pair
# define ac accumulate
# define mod 1000000007
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll power(ll x, ll y, ll p)
{
    ll res = 1;

    x = x % p;

    while (y > 0)
    {

        if (y & 1)
            res = (res*x) % p;

        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
bool sortinrev(const pair<ll,ll> &a,
               const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
typedef pair<int,int> ii;
// bool cmp(ii a,ii b)
// {
// 	if(a.ff==b.ff)
// 	{
// 		return a.ss>b.ss;
// 	}
// 	else
// 		a.ff<b.ff;
// }
   ll dp[27][200004]={0};
   bool visit[100000]={0};
int  main()
{
   #ifndef ONLINE_JUDGE
   freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
   #endif
   IOS;
   ll n,m;
   cin>>n>>m;

   vector<pair<ll,ll>>brr,crr,drr,err;
   for(ll i=0;i<m;i++)
   {
   		ll a,b,c;
   		cin>>a>>b>>c;
   		if(a==1)
   		{
   			brr.pb(mp(b,c));
   		}
   		else
   			crr.pb(mp(b,c));
   }

ll a,b;
 // cout<<"A\n";
  if(brr.size()!=0)
  {
  	sort(brr.begin(),brr.end());
  		 ll a=brr[0].ff,b=brr[0].ss;
	   for(ll i=0;i<brr.size();i++)
	   {
	   		ll flag=0;
	   		for(ll j=i;j<brr.size();j++)
	   		{
	   			if(brr[j].ff>b)
	   			{
	   				flag=-1;
	   				drr.pb(mp(a,b));
	   				a=brr[j].ff;
	   				b=brr[j].ss;
	   				i=j-1;
	   				break;
	   			}
	   			b=max(b,brr[j].ss);
	   		}
	   		if(flag==0)
	   		{
	   			drr.pb(mp(a,b));
	   			break;
	   		}
	   }
  }
    ll cnt=0;
		   for(ll i=0;i<drr.size();i++)
		   {
		   		for(ll j=0;j<crr.size();j++)
		   		{
		   			if(crr[j].ff>=drr[i].ff && crr[j].ss<=drr[i].ss)
		   			{
		   				cout<<"NO\n";
		   				return 0;
		   			}
		   		}
		   }
    cnt=6000002;
   ll ans[n+2];
   for(ll i=0;i<drr.size();i++)
   {
   //	cout<<drr[i].ff<<" "<<drr[i].ss<<endl;
   		for(ll j=drr[i].ff;j<=drr[i].ss;j++)
   		{
   			visit[j]=true;
   			ans[j]=cnt;
   			//cout<<j<<" "<<ans[j]<<endl;
   		}
   		cnt-=2;
   }
  if(drr.size()>0)
  for(ll i=0;i<drr.size()-1;i++)
  {
  	ll k=ans[drr[i].ss];
  		for(ll j=drr[i].ss+1;j<drr[i+1].ff;j++)
  		{
  			ans[j]=ans[j-1]-1;
  			visit[j]=true;
  		}
  }
   if(drr.size()>0)
  for(ll j=drr[drr.size()-1].ss+1;j<=n;j++)
  {
  		ans[j]=ans[j-1]-1;
  		visit[j]=true;
  }
   for(ll i=1;i<=n;i++)
   	if(visit[i]==0)
   		ans[i]=1e7-i;
   	cout<<"YES\n";
   	for(ll i=1;i<=n;i++)
   		cout<<ans[i]<<" ";

}


#include <bits/stdc++.h>
using namespace std;
# define ll  long long  int
# define ld  long double
# define pb push_back
# define pp pop_back
# define ff first
# define ss second
# define mp make_pair
# define ac accumulate
# define mod 1000000007
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll power(ll x, ll y, ll p)
{
    ll res = 1;

    x = x % p;

    while (y > 0)
    {

        if (y & 1)
            res = (res*x) % p;

        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
bool sortinrev(const pair<ll,ll> &a,
               const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
typedef pair<int,int> ii;
// bool cmp(ii a,ii b)
// {
// 	if(a.ff==b.ff)
// 	{
// 		return a.ss>b.ss;
// 	}
// 	else
// 		a.ff<b.ff;
// }
   ll dp[27][200004]={0};
int  main()
{
   #ifndef ONLINE_JUDGE
   freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
   #endif
   IOS;
   ll n,m;
   cin>>n>>m;
   vector<pair<ll,ll>>brr,crr,drr,err;
   for(ll i=0;i<m;i++)
   {
   		ll a,b,c;
   		cin>>a>>b>>c;
   		if(a==1)
   		{
   			brr.pb(mp(b,c));
   		}
   		else
   			crr.pb(mp(b,c));
   }
   sort(brr.begin(),brr.end());
   sort(crr.begin(),crr.end());
   ll a=brr[0].ff,b=brr[0].ss;
   for(ll i=0;i<brr.size();i++)
   {
   		ll flag=0;
   		for(ll j=i;j<brr.size();j++)
   		{
   			if(brr[j].ff>b)
   			{
   				flag=-1;
   				drr.pb(mp(a,b));
   				a=brr[j].ff;
   				b=brr[j].ss;
   				i=j-1;
   				break;
   			}
   			b=max(b,brr[j].ss);
   		}
   		if(flag==0)
   		{
   			drr.pb(mp(a,b));
   			break;
   		}
   }
   a=crr[0].ff;b=crr[0].ss;
    for(ll i=0;i<crr.size();i++)
   {
   		ll flag=0;
   		for(ll j=i;j<crr.size();j++)
   		{
   			if(crr[j].ff>b)
   			{
   				flag=-1;
   				err.pb(mp(a,b));
   				a=crr[j].ff;
   				b=crr[j].ss;
   				i=j-1;
   				break;
   			}
   			b=max(b,crr[j].ss);
   		}
   		if(flag==0)
   		{
   			err.pb(mp(a,b));
   			break;
   		}
   }
   ll cnt=0;
   for(ll i=0;i<drr.size();i++)
   {
   		for(ll j=0;j<err.size();j++)
   		{
   			if(err[j].ff>=drr[i].ff && err[j].ss<=drr[i].ss)
   			{
   				cout<<"NO\n";
   				return 0;
   			}
   		}
   }
   bool visit[100000]={0};
    cnt=2000;
   ll ans[n+2];
   for(ll i=0;i<drr.size();i++)
   {
   		for(ll j=drr[i].ff;j<=drr[i].ss;j++)
   		{
   			visit[j]=true;
   			ans[j]=cnt;
   		}
   		cnt-=2;
   }
   cnt=2001;
    for(ll i=0;i<err.size();i++)
   {
   		for(ll j=err[i].ff;j<=err[i].ss;j++)
   		{
   			if(visit[j]==true)
   				continue;
   			visit[j]=true;
   			ans[j]=cnt;
   		}
   		cnt-=2;
   }
   for(ll i=1;i<=n;i++)
   	if(visit[i]==0)
   		ans[i]=5000;
   	cout<<"YES\n";
   	for(auto i:ans)
   		cout<<i<<" ";

}


#include <bits/stdc++.h>
using namespace std;
# define ll  long long  int
# define ld  long double
# define pb push_back
# define pp pop_back
# define ff first
# define ss second
# define mp make_pair
# define ac accumulate
# define mod 1000000007
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll power(ll x, ll y, ll p)
{
    ll res = 1;

    x = x % p;

    while (y > 0)
    {

        if (y & 1)
            res = (res*x) % p;

        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
bool sortinrev(const pair<ll,ll> &a,
               const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
typedef pair<int,int> ii;
// bool cmp(ii a,ii b)
// {
// 	if(a.ff==b.ff)
// 	{
// 		return a.ss>b.ss;
// 	}
// 	else
// 		a.ff<b.ff;
// }
   ll dp[27][200004]={0};
int  main()
{
   #ifndef ONLINE_JUDGE
   freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
   #endif
   IOS;
   ll n,m;
   cin>>n>>m;
   vector<pair<ll,ll>>brr,crr,drr,err;
   for(ll i=0;i<m;i++)
   {
   		ll a,b,c;
   		cin>>a>>b>>c;
   		if(a==1)
   		{
   			brr.pb(mp(b,c));
   		}
   		else
   			crr.pb(mp(b,c));
   }
   sort(brr.begin(),brr.end());
   sort(crr.begin(),crr.end());
   ll a=brr[0].ff,b=brr[0].ss;
   for(ll i=0;i<brr.size();i++)
   {
   		ll flag=0;
   		for(ll j=i;j<brr.size();j++)
   		{
   			if(brr[j].ff>b)
   			{
   				flag=-1;
   				drr.pb(mp(a,b));
   				a=brr[j].ff;
   				b=brr[j].ss;
   				i=j-1;
   				break;
   			}
   			b=max(b,brr[j].ss);
   		}
   		if(flag==0)
   		{
   			drr.pb(mp(a,b));
   			break;
   		}
   }
   a=crr[0].ff;b=crr[0].ss;
    for(ll i=0;i<crr.size();i++)
   {
   		ll flag=0;
   		for(ll j=i;j<crr.size();j++)
   		{
   			if(crr[j].ff>b)
   			{
   				flag=-1;
   				err.pb(mp(a,b));
   				a=crr[j].ff;
   				b=crr[j].ss;
   				i=j-1;
   				break;
   			}
   			b=max(b,crr[j].ss);
   		}
   		if(flag==0)
   		{
   			err.pb(mp(a,b));
   			break;
   		}
   }
   ll cnt=0;
   for(ll i=0;i<drr.size();i++)
   {
   		for(ll j=0;j<err.size();j++)
   		{
   			if(err[j].ff>=drr[i].ff && err[j].ss<=drr[i].ss)
   			{
   				cout<<"NO\n";
   				return 0;
   			}
   		}
   }
   bool visit[100000]={0};
    cnt=2000;
   ll ans[n+2];
   for(ll i=0;i<drr.size();i++)
   {
   //	cout<<drr[i].ff<<" "<<drr[i].ss<<endl;
   		for(ll j=drr[i].ff;j<=drr[i].ss;j++)
   		{
   			visit[j]=true;
   			ans[j]=cnt;
   			//cout<<j<<" "<<ans[j]<<endl;
   		}
   		cnt-=2;
   }
   cnt=2001;
    for(ll i=0;i<err.size();i++)
   {
   //	cout<<err[i].ff<<" "<<err[i].ss<<endl;
   		for(ll j=err[i].ff;j<=err[i].ss;j++)
   		{
   			if(visit[j]==true)
   				continue;
   			visit[j]=true;
   			ans[j]=cnt;
   		}
   		cnt-=2;
   }
   for(ll i=1;i<=n;i++)
   	if(visit[i]==0)
   		ans[i]=5000;
   	cout<<"YES\n";
   	for(ll i=1;i<=n;i++)
   		cout<<ans[i]<<" ";

}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int maxn = 100009;
struct tree{
	int word;
	int p[26];
} T[maxn*20];
int p[maxn];
int r = 0;
int n, m, Q;
char s[29];
char t[29];

int getpa(int x){
	if (p[x] == x) return x;
	return p[x] = getpa(p[x]);
}

void build(int o){
	T[o].word = 0;
	memset(T[o].p, 0, sizeof T[o].p);
}

void insert(char s[], int rk){
	int len = strlen(s);
	int o = 0, t;
	for (int i=0; i<len; i++){
		t = s[i]-'a';
		if (!T[o].p[t]){
			build(++r);
			T[o].p[t] = r;
		}
		o = T[o].p[t];
	}
	T[o].word = rk;
}

int search(char s[]){
	int len = strlen(s);
	int o = 0;
	for (int i=0; i<len; i++)
		o = T[o].p[s[i]-'a'];
	return T[o].word;
}

int main(){
	scanf("%d%d%d", &n, &m, &Q);
	build(0);
	for (int i=1; i<=n; i++){
		scanf("%s", &s);
		insert(s, i);
		p[i] = i;
		p[i+n] = i+n;
	}
	int type, a, b, u, v;
	for (int i=1; i<=m; i++){
		scanf("%d%s%s", &type, &s, &t);
		a = search(s);
		b = search(t);
		if (type == 1){
			if (getpa(a+n) == getpa(b) || getpa(a) == getpa(b+n))
				puts("NO");
			else{
				puts("YES");
				p[getpa(a)] = getpa(b);
				p[getpa(a+n)] = getpa(b+n);
			}
		}
		else{
			if (getpa(a) == getpa(b) || getpa(a+n) == getpa(b+n))
				puts("NO");
			else{
				puts("YES");
				p[getpa(a+n)] = getpa(b);
				p[getpa(a)] = getpa(b+n);
			}
		}
	}
	for (int i=1; i<=Q; i++){
		scanf("%s%s", &s, &t);
		a = search(s);
		b = search(t);
		if (getpa(a) == getpa(b) || getpa(a+n) == getpa(b+n)) puts("1");
		else if (getpa(a+n) == getpa(b) || getpa(a) == getpa(b+n)) puts("2");
		else puts("3");
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int maxn = 100009;
struct tree{
	int word;
	int p[26];
} T[maxn*18];
int p[maxn];
int r = 0;
int n, m, Q;
char s[29];
char t[29];

int getpa(int x){
	if (p[x] == x) return x;
	return p[x] = getpa(p[x]);
}

void build(int o){
	T[o].word = 0;
	memset(T[o].p, 0, sizeof T[o].p);
}

void insert(char s[], int rk){
	int len = strlen(s);
	int o = 0, t;
	for (int i=0; i<len; i++){
		t = s[i]-'a';
		if (!T[o].p[t]){
			build(++r);
			T[o].p[t] = r;
		}
		o = T[o].p[t];
	}
	T[o].word = rk;
}

int search(char s[]){
	int len = strlen(s);
	int o = 0;
	for (int i=0; i<len; i++)
		o = T[o].p[s[i]-'a'];
	return T[o].word;
}

int main(){
	scanf("%d%d%d", &n, &m, &Q);
	build(0);
	for (int i=1; i<=n; i++){
		scanf("%s", &s);
		insert(s, i);
		p[i] = i;
		p[i+n] = i+n;
	}
	int type, a, b, u, v;
	for (int i=1; i<=m; i++){
		scanf("%d%s%s", &type, &s, &t);
		a = search(s);
		b = search(t);
		if (type == 1){
			if (getpa(a+n) == getpa(b) || getpa(a) == getpa(b+n))
				puts("NO");
			else{
				puts("YES");
				p[getpa(a)] = getpa(b);
				p[getpa(a+n)] = getpa(b+n);
			}
		}
		else{
			if (getpa(a) == getpa(b) || getpa(a+n) == getpa(b+n))
				puts("NO");
			else{
				puts("YES");
				p[getpa(a+n)] = getpa(b);
				p[getpa(a)] = getpa(b+n);
			}
		}
	}
	for (int i=1; i<=Q; i++){
		scanf("%s%s", &s, &t);
		a = search(s);
		b = search(t);
		if (getpa(a) == getpa(b) || getpa(a+n) == getpa(b+n)) puts("1");
		else if (getpa(a+n) == getpa(b) || getpa(a) == getpa(b+n)) puts("2");
		else puts("3");
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int maxn = 100009;
struct tree{
	int word;
	int p[26];
} T[maxn*29];
int p[maxn];
int r = 0;
int n, m, Q;
char s[29];
char t[29];

int getpa(int x){
	if (p[x] == x) return x;
	return p[x] = getpa(p[x]);
}

void build(int o){
	T[o].word = 0;
	memset(T[o].p, 0, sizeof T[o].p);
}

void insert(char s[], int rk){
	int len = strlen(s);
	int o = 0, t;
	for (int i=0; i<len; i++){
		t = s[i]-'a';
		if (!T[o].p[t]){
			build(++r);
			T[o].p[t] = r;
		}
		o = T[o].p[t];
	}
	T[o].word = rk;
}

int search(char s[]){
	int len = strlen(s);
	int o = 0;
	for (int i=0; i<len; i++)
		o = T[o].p[s[i]-'a'];
	return T[o].word;
}

int main(){
	scanf("%d%d%d", &n, &m, &Q);
	build(0);
	for (int i=1; i<=n; i++){
		scanf("%s", &s);
		insert(s, i);
		p[i] = i;
		p[i+n] = i+n;
	}
	int type, a, b, u, v;
	for (int i=1; i<=m; i++){
		scanf("%d%s%s", &type, &s, &t);
		a = search(s);
		b = search(t);
		if (type == 1){
			if (getpa(a+n) == getpa(b) || getpa(a) == getpa(b+n))
				puts("NO");
			else{
				puts("YES");
				p[getpa(a)] = getpa(b);
				p[getpa(a+n)] = getpa(b+n);
			}
		}
		else{
			if (getpa(a) == getpa(b) || getpa(a+n) == getpa(b+n))
				puts("NO");
			else{
				puts("YES");
				p[getpa(a+n)] = getpa(b);
				p[getpa(a)] = getpa(b+n);
			}
		}
	}
	for (int i=1; i<=Q; i++){
		scanf("%s%s", &s, &t);
		a = search(s);
		b = search(t);
		if (getpa(a) == getpa(b) || getpa(a+n) == getpa(b+n)) puts("1");
		else if (getpa(a+n) == getpa(b) || getpa(a) == getpa(b+n)) puts("2");
		else puts("3");
	}
	return 0;
}


#include <cstdio>
#include <string>
#include <map>
#include <vector>
#include <iostream>
using namespace std;
int father[100001],type[100001];
int findfather(int x)
{
    if(father[x]==x)
        return x;
    else return father[x]=findfather(father[x]);
}
map<string,int> mp;
vector<int> link[100001];
int main()
{
    int n,m,q,t,f1,f2,x1,x2;
    string s,s2;
    //scanf("%d%d%d\n",&n,&m,&q);
    cin>>n>>m>>q;
    for(int i=1;i<=n;i++)
    {
        cin>>s;
        mp[s]=i;
    }
    for(int i=1;i<=n;i++)
        father[i]=i;
    for(int i=1;i<=n;i++)
        type[i]=1;
    for(int i=1;i<=n;i++)
        link[i].push_back(i);
    for(int i=0;i<m;i++)
    {
        //scanf("%d ",&t);
        cin>>t;
        cin>>s>>s2;
        x1=mp[s];
        x2=mp[s2];
        f1=findfather(x1);
        f2=findfather(x2);
        if(f1==f2)
        {
            if(t==1&&type[x1]==type[x2])
                printf("YES\n");
            else if(t==1&&type[x1]!=type[x2])
                printf("NO\n");
            else if(t==2&&type[x1]==type[x2])
                printf("NO\n");
            else if(t==2&&type[x1]!=type[x2])
                printf("YES\n");
        }
        else
        {
            if((t==1&&type[x1]!=type[x2])||(t==2&&type[x1]==type[x2]))
            {
                for(int j=0;j<link[f2].size();j++)
                    type[link[f2][j]]=3-type[link[f2][j]];
            }
            father[f2]=f1;
            for(int j=0;j<link[f2].size();j++)
                link[x1].push_back(link[f2][j]);
            link[f2].clear();
            printf("YES\n");
        }
        //for(int i=1;i<=n;i++)
            //cout<<findfather(i)<<" ";
        //cout<<endl;
    }
    for(int i=0;i<q;i++)
    {
        cin>>s>>s2;
        x1=mp[s];
        x2=mp[s2];
        f1=findfather(x1);
        f2=findfather(x2);
        if(f1!=f2)
            printf("3\n");
        else if(f1==f2&&type[x1]==type[x2])
            printf("1\n");
        else printf("2\n");
    }
    return 0;
}


#include <cstdio>
#include <string>
#include <map>
#include <vector>
#include <iostream>
using namespace std;
int father[100001],type[100001];
int findfather(int x)
{
    if(father[x]==x)
        return x;
    else return father[x]=findfather(father[x]);
}
map<string,int> mp;
vector<int> link[100001];
int main()
{
    int n,m,q,t,f1,f2,x1,x2;
    string s,s2;
    scanf("%d%d%d\n",&n,&m,&q);
    //cin>>n>>m>>q;
    for(int i=1;i<=n;i++)
    {
        cin>>s;
        mp[s]=i;
    }
    for(int i=1;i<=n;i++)
        father[i]=i;
    for(int i=1;i<=n;i++)
        type[i]=1;
    for(int i=1;i<=n;i++)
        link[i].push_back(i);
    for(int i=0;i<m;i++)
    {
        scanf("%d ",&t);
        //cin>>t;
        cin>>s>>s2;
        x1=mp[s];
        x2=mp[s2];
        f1=findfather(x1);
        f2=findfather(x2);
        if(f1==f2)
        {
            if(t==1&&type[x1]==type[x2])
                printf("YES\n");
            else if(t==1&&type[x1]!=type[x2])
                printf("NO\n");
            else if(t==2&&type[x1]==type[x2])
                printf("NO\n");
            else if(t==2&&type[x1]!=type[x2])
                printf("YES\n");
        }
        else
        {
            if((t==1&&type[x1]!=type[x2])||(t==2&&type[x1]==type[x2]))
            {
                for(int i=0;i<link[f2].size();i++)
                    type[link[f2][i]]=3-type[link[f2][i]];
            }
            father[f2]=f1;
            for(int i=0;i<link[f2].size();i++)
                link[x1].push_back(link[f2][i]);
            link[f2].clear();
            printf("YES\n");
        }
        //for(int i=1;i<=n;i++)
            //cout<<findfather(i)<<" ";
        //cout<<endl;
    }
    for(int i=0;i<q;i++)
    {
        cin>>s>>s2;
        x1=mp[s];
        x2=mp[s2];
        f1=findfather(x1);
        f2=findfather(x2);
        if(f1!=f2)
            printf("3\n");
        else if(f1==f2&&type[x1]==type[x2])
            printf("1\n");
        else printf("2\n");
    }
    return 0;
}


#include <cstdio>
#include <string>
#include <map>
#include <vector>
#include <iostream>
using namespace std;
int father[100001],type[100001];
int findfather(int x)
{
    if(father[x]==x)
        return x;
    else return father[x]=findfather(father[x]);
}
map<string,int> mp;
//vector<int> link[100001];
int main()
{
    int n,m,q,t,f1,f2,x1,x2;
    string s,s2;
    //scanf("%d%d%d\n",&n,&m,&q);
    cin>>n>>m>>q;
    for(int i=1;i<=n;i++)
    {
        cin>>s;
        mp[s]=i;
    }
    for(int i=1;i<=n;i++)
        father[i]=i;
    for(int i=1;i<=n;i++)
        type[i]=1;
    //for(int i=1;i<=n;i++)
        //link[i].push_back(i);
    for(int i=0;i<m;i++)
    {
        //scanf("%d ",&t);
        cin>>t;
        cin>>s>>s2;
        x1=mp[s];
        x2=mp[s2];
        f1=findfather(x1);
        f2=findfather(x2);
        if(f1==f2)
        {
            if(t==1&&type[x1]==type[x2])
                printf("YES\n");
            else if(t==1&&type[x1]!=type[x2])
                printf("NO\n");
            else if(t==2&&type[x1]==type[x2])
                printf("NO\n");
            else if(t==2&&type[x1]!=type[x2])
                printf("YES\n");
        }
        else
        {
            if((t==1&&type[x1]!=type[x2])||(t==2&&type[x1]==type[x2]))
            {
                for(int j=1;j<=n;j++)
                    if(findfather(j)==f2)
                        type[j]=3-type[j];
            }
            father[f2]=f1;
            printf("YES\n");
        }
        //for(int i=1;i<=n;i++)
            //cout<<findfather(i)<<" ";
        //cout<<endl;
    }
    for(int i=0;i<q;i++)
    {
        cin>>s>>s2;
        x1=mp[s];
        x2=mp[s2];
        f1=findfather(x1);
        f2=findfather(x2);
        if(f1!=f2)
            printf("3\n");
        else if(f1==f2&&type[x1]==type[x2])
            printf("1\n");
        else printf("2\n");
    }
    return 0;
}


#include <cstdio>
#include <string>
#include <map>
#include <vector>
#include <iostream>
using namespace std;
int father[100001],type[100001];
int findfather(int x)
{
    if(father[x]==x)
        return x;
    else return father[x]=findfather(father[x]);
}
map<string,int> mp;
vector<int> link[100001];
int main()
{
    int n,m,q,t,f1,f2,x1,x2;
    string s,s2;
    //scanf("%d%d%d\n",&n,&m,&q);
    cin>>n>>m>>q;
    for(int i=1;i<=n;i++)
    {
        cin>>s;
        mp[s]=i;
    }
    for(int i=1;i<=n;i++)
        father[i]=i;
    for(int i=1;i<=n;i++)
        type[i]=1;
    for(int i=1;i<=n;i++)
        link[i].push_back(i);
    for(int i=0;i<m;i++)
    {
        //scanf("%d ",&t);
        cin>>t;
        cin>>s>>s2;
        x1=mp[s];
        x2=mp[s2];
        f1=findfather(x1);
        f2=findfather(x2);
        if(f1==f2)
        {
            if(t==1&&type[x1]==type[x2])
                printf("YES\n");
            else if(t==1&&type[x1]!=type[x2])
                printf("NO\n");
            else if(t==2&&type[x1]==type[x2])
                printf("NO\n");
            else if(t==2&&type[x1]!=type[x2])
                printf("YES\n");
        }
        else
        {
            if((t==1&&type[x1]!=type[x2])||(t==2&&type[x1]==type[x2]))
            {
                for(int i=0;i<link[f2].size();i++)
                    type[link[f2][i]]=3-type[link[f2][i]];
            }
            father[f2]=f1;
            for(int i=0;i<link[f2].size();i++)
                link[x1].push_back(link[f2][i]);
            link[f2].clear();
            printf("YES\n");
        }
        //for(int i=1;i<=n;i++)
            //cout<<findfather(i)<<" ";
        //cout<<endl;
    }
    for(int i=0;i<q;i++)
    {
        cin>>s>>s2;
        x1=mp[s];
        x2=mp[s2];
        f1=findfather(x1);
        f2=findfather(x2);
        if(f1!=f2)
            printf("3\n");
        else if(f1==f2&&type[x1]==type[x2])
            printf("1\n");
        else printf("2\n");
    }
    return 0;
}


#include <cstdio>
#include <string>
#include <map>
#include <vector>
#include <iostream>
using namespace std;
int father[200005];
int findfather(int x)
{
    if(father[x]==x)
        return x;
    else return father[x]=findfather(father[x]);
}
map<string,int> mp;
map<string,int> mp2;
int main()
{
    int n,m,q,t,f1,f2,x1,x2,f3,f4,x3,x4;
    string s,s2;
    cin>>n>>m>>q;
    for(int i=1;i<=n;i++)
    {
        cin>>s;
        mp[s]=i;
        mp2[s]=i+n;
    }
    for(int i=1;i<=2*n;i++)
        father[i]=i;
    for(int i=0;i<m;i++)
    {
        cin>>t;
        cin>>s>>s2;
        x1=mp[s];
        x2=mp[s2];
        x3=mp2[s];
        x4=mp2[s2];
        f1=findfather(x1);
        f2=findfather(x2);
        f3=findfather(x3);
        f4=findfather(x4);
        if(f1==f2||f3==f4)
        {
            if(t==1)
                printf("YES\n");
            else printf("NO\n");
        }
        else if(f1==f4||f2==f3)
        {
            if(t==2)
                printf("YES\n");
            else printf("NO\n");
        }
        else
        {
            if(t==1)
            {
                father[f2]=f1;
                father[f4]=f3;
            }
            else
            {
                father[f4]=f1;
                father[f3]=f2;
            }
            printf("YES\n");
        }
    }
    for(int i=0;i<q;i++)
    {
        cin>>s>>s2;
        x1=mp[s];
        x2=mp[s2];
        x3=mp2[s];
        x4=mp2[s2];
        f1=findfather(x1);
        f2=findfather(x2);
        f3=findfather(x3);
        f4=findfather(x4);
        if(f1!=f2&&f1!=f4&&f2!=f3&&f2!=f4)
            printf("3\n");
        else if(f1==f2||f3==f4)
            printf("1\n");
        else printf("2\n");
    }
    return 0;
}


#include <cstdio>
#include <string>
#include <map>
#include <vector>
#include <iostream>
using namespace std;
int father[100001],type[100001];
int findfather(int x)
{
    if(father[x]==x)
        return x;
    else return father[x]=findfather(father[x]);
}
map<string,int> mp;
vector<int> link[100001];
int main()
{
    int n,m,q,t,f1,f2,x1,x2;
    string s,s2;
    //scanf("%d%d%d\n",&n,&m,&q);
    cin>>n>>m>>q;
    for(int i=1;i<=n;i++)
    {
        cin>>s;
        mp[s]=i;
    }
    for(int i=1;i<=n;i++)
        father[i]=i;
    for(int i=1;i<=n;i++)
        type[i]=1;
    for(int i=1;i<=n;i++)
        link[i].push_back(i);
    for(int i=0;i<m;i++)
    {
        //scanf("%d ",&t);
        cin>>t;
        cin>>s>>s2;
        x1=mp[s];
        x2=mp[s2];
        f1=findfather(x1);
        f2=findfather(x2);
        if(f1==f2)
        {
            if(t==1&&type[x1]==type[x2])
                printf("YES\n");
            else if(t==1&&type[x1]!=type[x2])
                printf("NO\n");
            else if(t==2&&type[x1]==type[x2])
                printf("NO\n");
            else if(t==2&&type[x1]!=type[x2])
                printf("YES\n");
        }
        else
        {
            if((t==1&&type[x1]!=type[x2])||(t==2&&type[x1]==type[x2]))
            {
                for(int j=0;j<link[f2].size();j++)
                    type[link[f2][j]]=3-type[link[f2][j]];
            }
            father[f2]=f1;
            for(int j=0;j<link[f2].size();j++)
                link[f1].push_back(link[f2][j]);
            link[f2].clear();
            printf("YES\n");
        }
        //for(int i=1;i<=n;i++)
            //cout<<findfather(i)<<" ";
        //cout<<endl;
    }
    for(int i=0;i<q;i++)
    {
        cin>>s>>s2;
        x1=mp[s];
        x2=mp[s2];
        f1=findfather(x1);
        f2=findfather(x2);
        if(f1!=f2)
            printf("3\n");
        else if(f1==f2&&type[x1]==type[x2])
            printf("1\n");
        else printf("2\n");
    }
    return 0;
}


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

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define var(X) cerr << " --> " << #X << " = " << X << endl
#define arr(a,n) for(int i=0;i<n;i++){if(i==0) cout<<"Results for array "<< #a <<"\n";cout<<a[i]<<" ";} cout<<endl
#define arr1(a,n) for(int i=1;i<=n;i++){if(i==1) cout<<"Results for array "<< #a <<"\n";cout<<a[i]<<" ";} cout<<endl
#define PI 3.14159265

//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (4) << f << endl; Prints x.xxxx

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<pair<int,int> > vii;
const double eps = 1e-10, pi = acos(-1.0);

vi pset(100004);

int initset(int n)
{
	for(int i=0;i<n;i++)
	pset[i]=i;
}

int findset(int i)
{
	return (pset[i]==i)?i:(pset[i]=findset(pset[i]));
}

bool issame(int i,int j)
{
	return (findset(i)==findset(j));
}

void unionset(int i,int j)
{
	pset[findset(i)]=findset(j);
}

map<string,int> map1;
int ant[100005];
int ans[100005];

int main()
{
	int n,m,q,p1,p2,x;
	string s1,s2;
	cin>>n>>m>>q;
	for(int i=0;i<n;i++)
	{
		cin>>s1;
		map1[s1]=i;
	}
	initset(n);
	for(int i=0;i<n;i++)
	ant[i]=-1;
	for(int i=0;i<m;i++)
	{
		cin>>x;
		cin>>s1>>s2;
		p1=findset(map1[s1]);
		p2=findset(map1[s2]);
		if(x==1)
		{
			if(ant[p1]==p2 || ant[p2]==p1)
			ans[i]=0;
			else
			{
				ans[i]=1;
				unionset(p1,p2);
				if(ant[p1]!=-1 && ant[p2]!=-1)
				{
					unionset(ant[p1],ant[p2]);
					ant[p1]=findset(ant[p1]);
					ant[p2]=findset(ant[p2]);
				}
				else if(ant[p1]==-1)
				ant[p1]=ant[p2];
				else if(ant[p2]==-1)
				ant[p2]=ant[p1];
				ant[findset(p1)]=ant[p1];
			}
		}
		else
		{
			if(p1==p2)
			ans[i]=0;
			else
			{
				ans[i]=1;
				if(ant[p1]==-1 && ant[p2]==-1)
				{
					ant[p1]=p2;
					ant[p2]=p1;
				}
				else if(ant[p1]==-1)
				{
					unionset(p1,ant[p2]);
					ant[findset(p1)]=findset(p2);
					ant[findset(p2)]=findset(p1);
				}
				else if(ant[p2]==-1)
				{
					unionset(p2,ant[p1]);
					ant[findset(p1)]=findset(p2);
					ant[findset(p2)]=findset(p1);
				}
				else
				{
					unionset(p1,ant[p2]);
					unionset(p2,ant[p1]);
					ant[findset(p1)]=findset(p2);
					ant[findset(p2)]=findset(p1);
				}
			}
		}
	}

	for(int i=0;i<m;i++)
	if(ans[i]==0)
	cout<<"NO\n";
	else
	cout<<"YES\n";

	for(int i=0;i<q;i++)
	{
		cin>>s1>>s2;
		p1=findset(map1[s1]);
		p2=findset(map1[s2]);
		if(p1==p2)
		cout<<"1\n";
		else if(ant[p1]==p2 || ant[p2]==p1)
		cout<<"2\n";
		else
		cout<<"3\n";
	}
	return 0;
}


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

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define var(X) cerr << " --> " << #X << " = " << X << endl
#define arr(a,n) for(int i=0;i<n;i++){if(i==0) cout<<"Results for array "<< #a <<"\n";cout<<a[i]<<" ";} cout<<endl
#define arr1(a,n) for(int i=1;i<=n;i++){if(i==1) cout<<"Results for array "<< #a <<"\n";cout<<a[i]<<" ";} cout<<endl
#define PI 3.14159265

//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (4) << f << endl; Prints x.xxxx

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<pair<int,int> > vii;
const double eps = 1e-10, pi = acos(-1.0);

vi pset(100004);

int initset(int n)
{
	for(int i=0;i<n;i++)
	pset[i]=i;
}

int findset(int i)
{
	return (pset[i]==i)?i:(pset[i]=findset(pset[i]));
}

bool issame(int i,int j)
{
	return (findset(i)==findset(j));
}

void unionset(int i,int j)
{
	pset[findset(i)]=findset(j);
}

map<string,int> map1;
int ant[100005];
int ans[100005];

int main()
{
	int n,m,q,p1,p2,x;
	string s1,s2;
	cin>>n>>m>>q;
	for(int i=0;i<n;i++)
	{
		cin>>s1;
		map1[s1]=i;
	}
	initset(n);
	for(int i=0;i<n;i++)
	ant[i]=-1;
	for(int i=0;i<m;i++)
	{
		cin>>x;
		cin>>s1>>s2;
		p1=findset(map1[s1]);
		p2=findset(map1[s2]);
		if(x==1)
		{
			if(ant[p1]!=-1 && findset(ant[p1])==p2)
			ans[i]=0;
			else
			{
				ans[i]=1;
				unionset(p1,p2);
				if(ant[p1]!=-1 && ant[p2]!=-1)
				{
					unionset(ant[p1],ant[p2]);
					ant[p1]=findset(ant[p1]);
					ant[p2]=findset(ant[p2]);
				}
				else if(ant[p1]==-1)
				ant[p1]=ant[p2];
				else if(ant[p2]==-1)
				ant[p2]=ant[p1];
			}
		}
		else
		{
			if(p1==p2)
			ans[i]=0;
			else
			{
				ans[i]=1;
				if(ant[p1]==-1 && ant[p2]==-1)
				{
					ant[p1]=p2;
					ant[p2]=p1;
				}
				else if(ant[p1]==-1)
				{
					unionset(p1,ant[p2]);
					ant[findset(p1)]=findset(p2);
					ant[findset(p2)]=findset(p1);
				}
				else if(ant[p2]==-1)
				{
					unionset(p2,ant[p1]);
					ant[findset(p1)]=findset(p2);
					ant[findset(p2)]=findset(p1);
				}
				else
				{
					unionset(p1,ant[p2]);
					unionset(p2,ant[p1]);
					ant[findset(p1)]=findset(p2);
					ant[findset(p2)]=findset(p1);
				}
			}
		}
	}

	for(int i=0;i<m;i++)
	if(ans[i]==0)
	cout<<"NO\n";
	else
	cout<<"YES\n";

	for(int i=0;i<q;i++)
	{
		cin>>s1>>s2;
		p1=findset(map1[s1]);
		p2=findset(map1[s2]);
		if(p1==p2)
		cout<<"1\n";
		else if(ant[p1]!=-1 && findset(ant[p1])==p2)
		cout<<"2\n";
		else
		cout<<"3\n";
	}
	return 0;
}


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

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define var(X) cerr << " --> " << #X << " = " << X << endl
#define arr(a,n) for(int i=0;i<n;i++){if(i==0) cout<<"Results for array "<< #a <<"\n";cout<<a[i]<<" ";} cout<<endl
#define arr1(a,n) for(int i=1;i<=n;i++){if(i==1) cout<<"Results for array "<< #a <<"\n";cout<<a[i]<<" ";} cout<<endl
#define PI 3.14159265

//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (4) << f << endl; Prints x.xxxx

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<pair<int,int> > vii;
const double eps = 1e-10, pi = acos(-1.0);

vi pset(100004);

int initset(int n)
{
	for(int i=0;i<n;i++)
	pset[i]=i;
}

int findset(int i)
{
	return (pset[i]==i)?i:(pset[i]=findset(pset[i]));
}

bool issame(int i,int j)
{
	return (findset(i)==findset(j));
}

void unionset(int i,int j)
{
	pset[findset(i)]=findset(j);
}

map<string,int> map1;
int ant[100005];
int ans[100005];

int main()
{
	int n,m,q,p1,p2,x;
	string s1,s2;
	cin>>n>>m>>q;
	for(int i=0;i<n;i++)
	{
		cin>>s1;
		map1[s1]=i;
	}
	initset(n);
	for(int i=0;i<n;i++)
	ant[i]=-1;
	for(int i=0;i<m;i++)
	{
		cin>>x;
		cin>>s1>>s2;
		p1=findset(map1[s1]);
		p2=findset(map1[s2]);
		if(x==1)
		{
			if(ant[p1]==p2 || ant[p2]==p1)
			ans[i]=0;
			else
			{
				ans[i]=1;
				unionset(p1,p2);
			}
		}
		else
		{
			if(p1==p2)
			ans[i]=0;
			else
			{
				ans[i]=1;
				if(ant[p1]==-1 && ant[p2]==-1)
				{
					ant[p1]=p2;
					ant[p2]=p1;
				}
				else if(ant[p1]==-1)
				{
					unionset(p1,ant[p2]);
					ant[findset(p1)]=findset(p2);
				}
				else if(ant[p2]==-1)
				{
					unionset(p2,ant[p1]);
					ant[findset(p2)]=findset(p1);
				}
				else
				{
					unionset(p1,ant[p2]);
					unionset(p2,ant[p1]);
				}
			}
		}
	}

	for(int i=0;i<m;i++)
	if(ans[i]==0)
	cout<<"NO\n";
	else
	cout<<"YES\n";

	for(int i=0;i<q;i++)
	{
		cin>>s1>>s2;
		p1=findset(map1[s1]);
		p2=findset(map1[s2]);
		if(p1==p2)
		cout<<"1\n";
		else if(ant[p1]==p2 || ant[p2]==p1)
		cout<<"2\n";
		else
		cout<<"3\n";
	}
	return 0;
}


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

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define var(X) cerr << " --> " << #X << " = " << X << endl
#define arr(a,n) for(int i=0;i<n;i++){if(i==0) cout<<"Results for array "<< #a <<"\n";cout<<a[i]<<" ";} cout<<endl
#define arr1(a,n) for(int i=1;i<=n;i++){if(i==1) cout<<"Results for array "<< #a <<"\n";cout<<a[i]<<" ";} cout<<endl
#define PI 3.14159265

//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (4) << f << endl; Prints x.xxxx

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<pair<int,int> > vii;
const double eps = 1e-10, pi = acos(-1.0);

vi pset(100004);

int initset(int n)
{
	for(int i=0;i<n;i++)
	pset[i]=i;
}

int findset(int i)
{
	return (pset[i]==i)?i:(pset[i]=findset(pset[i]));
}

bool issame(int i,int j)
{
	return (findset(i)==findset(j));
}

void unionset(int i,int j)
{
	pset[findset(i)]=findset(j);
}

map<string,int> map1;
int ant[100005];
int ans[100005];

int main()
{
	int n,m,q,p1,p2,x;
	string s1,s2;
	cin>>n>>m>>q;
	for(int i=0;i<n;i++)
	{
		cin>>s1;
		map1[s1]=i;
	}
	initset(n);
	for(int i=0;i<n;i++)
	ant[i]=-1;
	for(int i=0;i<m;i++)
	{
		cin>>x;
		cin>>s1>>s2;
		p1=findset(map1[s1]);
		p2=findset(map1[s2]);
		if(x==1)
		{
			if(ant[p1]!=-1 && p2==findset(ant[p1]))
			ans[i]=0;
			else
			{
				ans[i]=1;
				if(ant[p1]==-1 && ant[p2]!=-1)
				ant[p1]=ant[p2];
				else if(ant[p2]==-1 && ant[p1]!=-1)
				ant[p2]=ant[p1];
				else if(ant[p1]!=-1 && ant[p2]!=-1)
				unionset(findset(ant[p1]),findset(ant[p2]));
				unionset(p1,p2);
				ant[findset(p1)]=ant[p1];
			}
		}
		else
		{
			if(p1==p2)
			ans[i]=0;
			else
			{
				ans[i]=1;
				if(ant[p2]!=-1)
				{
					unionset(p1,ant[p2]);
				}
				if(ant[p1]!=-1)
				{
					unionset(p2,ant[p1]);
				}
				ant[p1]=findset(p2);
				ant[p2]=findset(p1);
			}
		}
	}

	for(int i=0;i<m;i++)
	if(ans[i]==0)
	cout<<"NO\n";
	else
	cout<<"YES\n";

	for(int i=0;i<q;i++)
	{
		cin>>s1>>s2;
		p1=findset(map1[s1]);
		p2=findset(map1[s2]);
		if(p1==p2)
		cout<<"1\n";
		else if(ant[p1]!=-1 && p2==findset(ant[p1]))
		cout<<"2\n";
		else
		cout<<"3\n";
	}
	return 0;
}


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

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define var(X) cerr << " --> " << #X << " = " << X << endl
#define arr(a,n) for(int i=0;i<n;i++){if(i==0) cout<<"Results for array "<< #a <<"\n";cout<<a[i]<<" ";} cout<<endl
#define arr1(a,n) for(int i=1;i<=n;i++){if(i==1) cout<<"Results for array "<< #a <<"\n";cout<<a[i]<<" ";} cout<<endl
#define PI 3.14159265

//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (4) << f << endl; Prints x.xxxx

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<pair<int,int> > vii;
const double eps = 1e-10, pi = acos(-1.0);

vi pset(100004);

int initset(int n)
{
	for(int i=0;i<n;i++)
	pset[i]=i;
}

int findset(int i)
{
	return (pset[i]==i)?i:(pset[i]=findset(pset[i]));
}

bool issame(int i,int j)
{
	return (findset(i)==findset(j));
}

void unionset(int i,int j)
{
	pset[findset(i)]=findset(j);
}

map<string,int> map1;
int ant[100005];
int ans[100005];

int main()
{
	int n,m,q,p1,p2,x;
	string s1,s2;
	cin>>n>>m>>q;
	for(int i=0;i<n;i++)
	{
		cin>>s1;
		map1[s1]=i;
	}
	initset(n);
	for(int i=0;i<n;i++)
	ant[i]=-1;
	for(int i=0;i<m;i++)
	{
		cin>>x;
		cin>>s1>>s2;
		p1=findset(map1[s1]);
		p2=findset(map1[s2]);
		if(x==1)
		{
			if(ant[p1]==p2 || ant[p2]==p1)
			ans[i]=0;
			else
			{
				ans[i]=1;
				unionset(p1,p2);
				if(ant[p1]!=-1 && ant[p2]!=-1)
				{
					unionset(ant[p1],ant[p2]);
					ant[p1]=findset(ant[p1]);
					ant[p2]=findset(ant[p2]);
				}
				else if(ant[p1]==-1)
				ant[p1]=ant[p2];
				else if(ant[p2]==-1)
				ant[p2]=ant[p1];
			}
		}
		else
		{
			if(p1==p2)
			ans[i]=0;
			else
			{
				ans[i]=1;
				if(ant[p1]==-1 && ant[p2]==-1)
				{
					ant[p1]=p2;
					ant[p2]=p1;
				}
				else if(ant[p1]==-1)
				{
					unionset(p1,ant[p2]);
					ant[findset(p1)]=findset(p2);
					ant[findset(p2)]=findset(p1);
				}
				else if(ant[p2]==-1)
				{
					unionset(p2,ant[p1]);
					ant[findset(p1)]=findset(p2);
					ant[findset(p2)]=findset(p1);
				}
				else
				{
					unionset(p1,ant[p2]);
					unionset(p2,ant[p1]);
					ant[findset(p1)]=findset(p2);
					ant[findset(p2)]=findset(p1);
				}
			}
		}
	}

	for(int i=0;i<m;i++)
	if(ans[i]==0)
	cout<<"NO\n";
	else
	cout<<"YES\n";

	for(int i=0;i<q;i++)
	{
		cin>>s1>>s2;
		p1=findset(map1[s1]);
		p2=findset(map1[s2]);
		if(p1==p2)
		cout<<"1\n";
		else if(ant[p1]==p2 || ant[p2]==p1)
		cout<<"2\n";
		else
		cout<<"3\n";
	}
	return 0;
}


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

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define var(X) cerr << " --> " << #X << " = " << X << endl
#define arr(a,n) for(int i=0;i<n;i++){if(i==0) cout<<"Results for array "<< #a <<"\n";cout<<a[i]<<" ";} cout<<endl
#define arr1(a,n) for(int i=1;i<=n;i++){if(i==1) cout<<"Results for array "<< #a <<"\n";cout<<a[i]<<" ";} cout<<endl
#define PI 3.14159265

//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (4) << f << endl; Prints x.xxxx

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<pair<int,int> > vii;
const double eps = 1e-10, pi = acos(-1.0);

vi pset(100004);

int initset(int n)
{
	for(int i=0;i<n;i++)
	pset[i]=i;
}

int findset(int i)
{
	return (pset[i]==i)?i:(pset[i]=findset(pset[i]));
}

bool issame(int i,int j)
{
	return (findset(i)==findset(j));
}

void unionset(int i,int j)
{
	pset[findset(i)]=findset(j);
}

map<string,int> map1;
int ant[100005];
int ans[100005];

int main()
{
	int n,m,q,p1,p2,x;
	string s1,s2;
	cin>>n>>m>>q;
	for(int i=0;i<n;i++)
	{
		cin>>s1;
		map1[s1]=i;
	}
	initset(n);
	for(int i=0;i<n;i++)
	ant[i]=-1;
	for(int i=0;i<m;i++)
	{
		cin>>x;
		cin>>s1>>s2;
		p1=findset(map1[s1]);
		p2=findset(map1[s2]);
		if(x==1)
		{
			if(ant[p1]!=-1 && p2==findset(ant[p1]))
			ans[i]=0;
			else
			{
				ans[i]=1;
				if(ant[p1]==-1 && ant[p2]!=-1)
				ant[p1]=ant[p2];
				else if(ant[p2]==-1 && ant[p1]!=-1)
				ant[p2]=ant[p1];
				else if(ant[p1]!=-1 && ant[p2]!=-1)
				unionset(findset(ant[p1]),findset(ant[p2]));
				unionset(p1,p2);
				ant[findset(p1)]=ant[p1];
			}
		}
		else
		{
			if(p1==p2)
			ans[i]=0;
			else
			{
				ans[i]=1;
				if(ant[p2]!=-1)
				{
					unionset(ant[p2],p1);
				}
				if(ant[p1]!=-1)
				{
					unionset(ant[p1],p2);
				}
				ant[p1]=findset(p2);
				ant[p2]=findset(p1);
			}
		}
	}

	for(int i=0;i<m;i++)
	if(ans[i]==0)
	cout<<"NO\n";
	else
	cout<<"YES\n";

	for(int i=0;i<q;i++)
	{
		cin>>s1>>s2;
		p1=findset(map1[s1]);
		p2=findset(map1[s2]);
		if(p1==p2)
		cout<<"1\n";
		else if(ant[p1]!=-1 && p2==findset(ant[p1]))
		cout<<"2\n";
		else
		cout<<"3\n";
	}
	return 0;
}


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

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define var(X) cerr << " --> " << #X << " = " << X << endl
#define arr(a,n) for(int i=0;i<n;i++){if(i==0) cout<<"Results for array "<< #a <<"\n";cout<<a[i]<<" ";} cout<<endl
#define arr1(a,n) for(int i=1;i<=n;i++){if(i==1) cout<<"Results for array "<< #a <<"\n";cout<<a[i]<<" ";} cout<<endl
#define PI 3.14159265

//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (4) << f << endl; Prints x.xxxx

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<pair<int,int> > vii;
const double eps = 1e-10, pi = acos(-1.0);

vi pset(100004);

int initset(int n)
{
	for(int i=0;i<n;i++)
	pset[i]=i;
}

int findset(int i)
{
	return (pset[i]==i)?i:(pset[i]=findset(pset[i]));
}

bool issame(int i,int j)
{
	return (findset(i)==findset(j));
}

void unionset(int i,int j)
{
	pset[findset(i)]=findset(j);
}

map<string,int> map1;
int ant[100005];
int ans[100005];

int main()
{
	int n,m,q,p1,p2,x;
	string s1,s2;
	cin>>n>>m>>q;
	for(int i=0;i<n;i++)
	{
		cin>>s1;
		map1[s1]=i;
	}
	initset(n);
	for(int i=0;i<n;i++)
	ant[i]=-1;
	for(int i=0;i<m;i++)
	{
		cin>>x;
		cin>>s1>>s2;
		p1=findset(map1[s1]);
		p2=findset(map1[s2]);
		if(x==1)
		{
			if(ant[p1]==p2 || ant[p2]==p1)
			ans[i]=0;
			else
			{
				ans[i]=1;
				unionset(p1,p2);
				if(ant[p1]==-1 && ant[p2]!=-1)
				ant[p1]=ant[p2];
				else if(ant[p2]==-1 && ant[p1]!=-1)
				ant[p2]=ant[p1];
				else
				unionset(findset(p1),findset(p2));
				unionset(p1,p2);
				ant[findset(p1)]=ant[p1];
			}
		}
		else
		{
			if(p1==p2)
			ans[i]=0;
			else
			{
				ans[i]=1;
				if(ant[p2]!=-1)
				{
					unionset(p1,ant[p2]);
				}
				if(ant[p1]!=-1)
				{
					unionset(p2,ant[p1]);
				}
				ant[p1]=findset(p2);
				ant[p2]=findset(p1);
			}
		}
	}

	for(int i=0;i<m;i++)
	if(ans[i]==0)
	cout<<"NO\n";
	else
	cout<<"YES\n";

	for(int i=0;i<q;i++)
	{
		cin>>s1>>s2;
		p1=findset(map1[s1]);
		p2=findset(map1[s2]);
		if(p1==p2)
		cout<<"1\n";
		else if(ant[p1]==p2 || ant[p2]==p1)
		cout<<"2\n";
		else
		cout<<"3\n";
	}
	return 0;
}


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

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define var(X) cerr << " --> " << #X << " = " << X << endl
#define arr(a,n) for(int i=0;i<n;i++){if(i==0) cout<<"Results for array "<< #a <<"\n";cout<<a[i]<<" ";} cout<<endl
#define arr1(a,n) for(int i=1;i<=n;i++){if(i==1) cout<<"Results for array "<< #a <<"\n";cout<<a[i]<<" ";} cout<<endl
#define PI 3.14159265

//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (4) << f << endl; Prints x.xxxx

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<pair<int,int> > vii;
const double eps = 1e-10, pi = acos(-1.0);

vi pset(100004);

int initset(int n)
{
	for(int i=0;i<n;i++)
	pset[i]=i;
}

int findset(int i)
{
	return (pset[i]==i)?i:(pset[i]=findset(pset[i]));
}

bool issame(int i,int j)
{
	return (findset(i)==findset(j));
}

void unionset(int i,int j)
{
	pset[findset(i)]=findset(j);
}

map<string,int> map1;
int ant[100005];
int ans[100005];

int main()
{
	int n,m,q,p1,p2,x;
	string s1,s2;
	cin>>n>>m>>q;
	for(int i=0;i<n;i++)
	{
		cin>>s1;
		map1[s1]=i;
	}
	initset(n);
	for(int i=0;i<n;i++)
	ant[i]=-1;
	for(int i=0;i<m;i++)
	{
		cin>>x;
		cin>>s1>>s2;
		p1=findset(map1[s1]);
		p2=findset(map1[s2]);
		if(x==1)
		{
			if(ant[p1]!=-1 && findset(ant[p1])==p2)
			ans[i]=0;
			else
			{
				ans[i]=1;
				unionset(p1,p2);
				if(ant[p1]!=-1 && ant[p2]!=-1)
				{
					unionset(ant[p1],ant[p2]);
					ant[p1]=findset(ant[p1]);
					ant[p2]=findset(ant[p2]);
				}
				else if(ant[p1]==-1)
				ant[p1]=ant[p2];
				else if(ant[p2]==-1)
				ant[p2]=ant[p1];
				ant[findset(p1)]=ant[p1];
			}
		}
		else
		{
			if(p1==p2)
			ans[i]=0;
			else
			{
				ans[i]=1;
				if(ant[p1]==-1 && ant[p2]==-1)
				{
					ant[p1]=p2;
					ant[p2]=p1;
				}
				else if(ant[p1]==-1)
				{
					unionset(p1,ant[p2]);
					ant[findset(p1)]=findset(p2);
					ant[findset(p2)]=findset(p1);
				}
				else if(ant[p2]==-1)
				{
					unionset(p2,ant[p1]);
					ant[findset(p1)]=findset(p2);
					ant[findset(p2)]=findset(p1);
				}
				else
				{
					unionset(p1,ant[p2]);
					unionset(p2,ant[p1]);
					ant[findset(p1)]=findset(p2);
					ant[findset(p2)]=findset(p1);
				}
			}
		}
	}

	for(int i=0;i<m;i++)
	if(ans[i]==0)
	cout<<"NO\n";
	else
	cout<<"YES\n";

	for(int i=0;i<q;i++)
	{
		cin>>s1>>s2;
		p1=findset(map1[s1]);
		p2=findset(map1[s2]);
		if(p1==p2)
		cout<<"1\n";
		else if(ant[p1]!=-1 && findset(ant[p1])==p2)
		cout<<"2\n";
		else
		cout<<"3\n";
	}
	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <iomanip>
#include <queue>
#include <deque>
#include <set>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <string>

using namespace std;

typedef long long ll;

const int MAX_N = 1e5+10;
const ll INF = 1e18;
const ll MOD = 1e9+7;

int n,m,q,par[MAX_N],en[MAX_N];
map<string,int>MAP;
set<int>cc[MAX_N];

void join(int x,int y) {
    x = par[x];
    y = par[y];

    if(cc[y].size() > cc[x].size()) swap(x,y);
    while(cc[y].size() > 0) {
    	int node = *cc[y].begin();
    	cc[y].erase(cc[y].begin());
    	par[node] = x;
    	cc[x].insert(node);
    }
    cc[y].clear();

    int xx = en[x];
    int yy = en[y];
    if(xx == -1 && yy == -1)
    	return;
    if(xx == -1) {
    	en[x] = yy;
    	return;
    }
    if(yy == -1) {
    	en[x] = xx;
    	return;
    }

    if(cc[yy].size() > cc[xx].size()) swap(xx,yy);
    while(cc[yy].size() > 0) {
    	int node = *cc[yy].begin();
    	cc[yy].erase(cc[yy].begin());
    	par[node] = xx;
    	cc[xx].insert(node);
    }
    cc[yy].clear();

    en[x] = xx;
    en[xx] = x;
}

void disjoin(int x,int y) {
    x = par[x];
    y = par[y];
    int xx = en[x];
    int yy = en[y];

    if(yy != -1) {
    	if(cc[yy].size() > cc[x].size()) swap(x,yy);
	    while(cc[yy].size() > 0) {
	    	int node = *cc[yy].begin();
	    	cc[yy].erase(cc[yy].begin());
	    	par[node] = x;
	    	cc[x].insert(node);
    	}
    	cc[yy].clear();
    }

     if(xx != -1) {
    	if(cc[xx].size() > cc[y].size()) swap(xx,y);
	    while(cc[xx].size() > 0) {
	    	int node = *cc[xx].begin();
	    	cc[xx].erase(cc[xx].begin());
	    	par[node] = y;
	    	cc[y].insert(node);
    	}
    	cc[xx].clear();
    }
    en[x] = y;
    en[y] = x;
}

void kruskal() {
    for(int i = 1 ; i <= n ; i++) {
        par[i] = i;
        cc[i].insert(i);
        en[i] = -1;
    }
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>q;

	for(int i = 1 ; i <= n ; i++) {
		string s;
		cin>>s;
		MAP[s] = i;
	}
	kruskal();
	for(int i = 1 ; i <= m ; i++) {
		int t;
		string s,f;
		cin>>t>>s>>f;
		int a = MAP[s];
		int b = MAP[f];
		if(t == 1) {
			if(par[a] == par[b]) {
				cout<<"YES"<<endl;
				continue;
			}
			if(en[a] != -1) {
				int p = en[a];
				if(*cc[p].lower_bound(b) == b) {
					cout<<"NO"<<endl;
					continue;
				}
			}
			join(a,b);
			cout<<"YES"<<endl;
		}
		else {
			if(en[par[a]] == par[b]) {
				cout<<"YES"<<endl;
				continue;
			}
			if(par[a] == par[b]) {
				cout<<"NO"<<endl;
				continue;
			}
			disjoin(a,b);
			cout<<"YES"<<endl;
		}
	}
	for(int i = 1 ; i <= q ; i++) {
		string s,f;
		cin>>s>>f;
		int a = MAP[s];
		int b = MAP[f];
		if(par[a] == par[b])
			cout<<1<<endl;
		else if(en[par[a]] == par[b])
			cout<<2<<endl;
		else
			cout<<3<<endl;
	}

}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <iomanip>
#include <queue>
#include <deque>
#include <set>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <string>

using namespace std;

typedef long long ll;

const int MAX_N = 1e5+10;
const ll INF = 1e18;
const ll MOD = 1e9+7;

int n,m,q,par[MAX_N],en[MAX_N];
map<string,int>MAP;
set<int>cc[MAX_N];

void join(int x,int y) {
    x = par[x];
    y = par[y];

    if(cc[y].size() > cc[x].size()) swap(x,y);
    while(cc[y].size() > 0) {
    	int node = *cc[y].begin();
    	cc[y].erase(cc[y].begin());
    	par[node] = x;
    	cc[x].insert(node);
    }
    cc[y].clear();

    int xx = en[x];
    int yy = en[y];
    if(xx == -1 && yy == -1)
    	return;
    if(xx == -1) {
    	en[x] = yy;
    	return;
    }
    if(yy == -1) {
    	en[x] = xx;
    	return;
    }

    if(cc[yy].size() > cc[xx].size()) swap(xx,yy);
    while(cc[yy].size() > 0) {
    	int node = *cc[yy].begin();
    	cc[yy].erase(cc[yy].begin());
    	par[node] = xx;
    	cc[xx].insert(node);
    }
    cc[yy].clear();

    en[x] = xx;
}

void disjoin(int x,int y) {
    x = par[x];
    y = par[y];
    int xx = en[x];
    int yy = en[y];

    if(yy != -1) {
    	if(cc[yy].size() > cc[x].size()) swap(x,yy);
	    while(cc[yy].size() > 0) {
	    	int node = *cc[yy].begin();
	    	cc[yy].erase(cc[yy].begin());
	    	par[node] = x;
	    	cc[x].insert(node);
    	}
    	cc[yy].clear();
    }

     if(xx != -1) {
    	if(cc[xx].size() > cc[y].size()) swap(xx,y);
	    while(cc[xx].size() > 0) {
	    	int node = *cc[xx].begin();
	    	cc[xx].erase(cc[xx].begin());
	    	par[node] = y;
	    	cc[y].insert(node);
    	}
    	cc[xx].clear();
    }
    en[x] = y;
    en[y] = x;
}

void kruskal() {
    for(int i = 1 ; i <= n ; i++) {
        par[i] = i;
        cc[i].insert(i);
        en[i] = -1;
    }
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>q;

	for(int i = 1 ; i <= n ; i++) {
		string s;
		cin>>s;
		MAP[s] = i;
	}
	kruskal();
	for(int i = 1 ; i <= m ; i++) {
		int t;
		string s,f;
		cin>>t>>s>>f;
		int a = MAP[s];
		int b = MAP[f];
		if(t == 1) {
			if(par[a] == par[b]) {
				cout<<"YES"<<endl;
				continue;
			}
			if(en[a] != -1) {
				int p = en[a];
				if(*cc[p].lower_bound(b) == b) {
					cout<<"NO"<<endl;
					continue;
				}
			}
			join(a,b);
			cout<<"YES"<<endl;
		}
		else {
			if(en[par[a]] == par[b]) {
				cout<<"YES"<<endl;
				continue;
			}
			if(par[a] == par[b]) {
				cout<<"NO"<<endl;
				continue;
			}
			disjoin(a,b);
			cout<<"YES"<<endl;
		}
	}
	for(int i = 1 ; i <= q ; i++) {
		string s,f;
		cin>>s>>f;
		int a = MAP[s];
		int b = MAP[f];
		if(par[a] == par[b])
			cout<<1<<endl;
		else if(en[par[a]] == par[b])
			cout<<2<<endl;
		else
			cout<<3<<endl;
	}

}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <iomanip>
#include <queue>
#include <deque>
#include <set>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <string>

using namespace std;

typedef long long ll;

const int MAX_N = 1e5+10;
const ll INF = 1e18;
const ll MOD = 1e9+7;

int n,m,q,par[MAX_N],en[MAX_N];
map<string,int>MAP;
set<int>cc[MAX_N];

void join(int x,int y) {
    x = par[x];
    y = par[y];

    if(cc[y].size() > cc[x].size()) swap(x,y);
    while(cc[y].size() > 0) {
    	int node = *cc[y].begin();
    	cc[y].erase(cc[y].begin());
    	par[node] = x;
    	cc[x].insert(node);
    }
    cc[y].clear();

    int xx = en[x];
    int yy = en[y];
    if(xx == -1 && yy == -1)
    	return;
    if(xx == -1) {
    	en[x] = yy;
    	en[yy] = x;
    	return;
    }
    if(yy == -1) {
    	en[x] = xx;
    	en[xx] = x;
    	return;
    }

    if(cc[yy].size() > cc[xx].size()) swap(xx,yy);
    while(cc[yy].size() > 0) {
    	int node = *cc[yy].begin();
    	cc[yy].erase(cc[yy].begin());
    	par[node] = xx;
    	cc[xx].insert(node);
    }
    cc[yy].clear();

    en[x] = xx;
    en[xx] = x;
}

void disjoin(int x,int y) {
    x = par[x];
    y = par[y];
    int xx = en[x];
    int yy = en[y];

    if(yy != -1) {
    	if(cc[yy].size() > cc[x].size()) swap(x,yy);
	    while(cc[yy].size() > 0) {
	    	int node = *cc[yy].begin();
	    	cc[yy].erase(cc[yy].begin());
	    	par[node] = x;
	    	cc[x].insert(node);
    	}
    	cc[yy].clear();
    }

     if(xx != -1) {
    	if(cc[xx].size() > cc[y].size()) swap(xx,y);
	    while(cc[xx].size() > 0) {
	    	int node = *cc[xx].begin();
	    	cc[xx].erase(cc[xx].begin());
	    	par[node] = y;
	    	cc[y].insert(node);
    	}
    	cc[xx].clear();
    }
    en[x] = y;
    en[y] = x;
}

void kruskal() {
    for(int i = 1 ; i <= n ; i++) {
        par[i] = i;
        cc[i].insert(i);
        en[i] = -1;
    }
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>q;

	for(int i = 1 ; i <= n ; i++) {
		string s;
		cin>>s;
		MAP[s] = i;
	}
	kruskal();
	for(int i = 1 ; i <= m ; i++) {
		int t;
		string s,f;
		cin>>t>>s>>f;
		int a = MAP[s];
		int b = MAP[f];
		if(t == 1) {
			if(par[a] == par[b]) {
				cout<<"YES"<<endl;
				continue;
			}
			if(en[par[a]] != -1) {
				int p = en[par[a]];
				if(p == par[b]) {
					cout<<"NO"<<endl;
					continue;
				}
			}
			join(a,b);
			cout<<"YES"<<endl;
		}
		else {
			if(en[par[a]] == par[b]) {
				cout<<"YES"<<endl;
				continue;
			}
			if(par[a] == par[b]) {
				cout<<"NO"<<endl;
				continue;
			}
			disjoin(a,b);
			cout<<"YES"<<endl;
		}
	}
	for(int i = 1 ; i <= q ; i++) {
		string s,f;
		cin>>s>>f;
		int a = MAP[s];
		int b = MAP[f];
		if(par[a] == par[b])
			cout<<1<<endl;
		else if(en[par[a]] == par[b])
			cout<<2<<endl;
		else
			cout<<3<<endl;
	}

}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <iomanip>
#include <queue>
#include <deque>
#include <set>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <string>

using namespace std;

typedef long long ll;

const int MAX_N = 1e5+10;
const ll INF = 1e18;
const ll MOD = 1e9+7;

int n,m,q,par[MAX_N],en[MAX_N];
map<string,int>MAP;
set<int>cc[MAX_N];

void join(int x,int y) {
    x = par[x];
    y = par[y];

    if(cc[y].size() > cc[x].size()) swap(x,y);
    while(cc[y].size() > 0) {
    	int node = *cc[y].begin();
    	cc[y].erase(cc[y].begin());
    	par[node] = x;
    	cc[x].insert(node);
    }
    cc[y].clear();

    int xx = en[x];
    int yy = en[y];
    if(xx == -1 && yy == -1)
    	return;
    if(xx == -1) {
    	en[x] = yy;
    	en[yy] = x;
    	return;
    }
    if(yy == -1) {
    	en[x] = xx;
    	en[xx] = x;
    	return;
    }

    if(cc[yy].size() > cc[xx].size()) swap(xx,yy);
    while(cc[yy].size() > 0) {
    	int node = *cc[yy].begin();
    	cc[yy].erase(cc[yy].begin());
    	par[node] = xx;
    	cc[xx].insert(node);
    }
    cc[yy].clear();

    en[x] = xx;
    en[xx] = x;
}

void disjoin(int x,int y) {
    x = par[x];
    y = par[y];
    int xx = en[x];
    int yy = en[y];

    if(yy != -1) {
    	if(cc[yy].size() > cc[x].size()) swap(x,yy);
	    while(cc[yy].size() > 0) {
	    	int node = *cc[yy].begin();
	    	cc[yy].erase(cc[yy].begin());
	    	par[node] = x;
	    	cc[x].insert(node);
    	}
    	cc[yy].clear();
    }

     if(xx != -1) {
    	if(cc[xx].size() > cc[y].size()) swap(xx,y);
	    while(cc[xx].size() > 0) {
	    	int node = *cc[xx].begin();
	    	cc[xx].erase(cc[xx].begin());
	    	par[node] = y;
	    	cc[y].insert(node);
    	}
    	cc[xx].clear();
    }
    en[x] = y;
    en[y] = x;
}

void kruskal() {
    for(int i = 1 ; i <= n ; i++) {
        par[i] = i;
        cc[i].insert(i);
        en[i] = -1;
    }
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>q;

	for(int i = 1 ; i <= n ; i++) {
		string s;
		cin>>s;
		MAP[s] = i;
	}
	kruskal();
	for(int i = 1 ; i <= m ; i++) {
		int t;
		string s,f;
		cin>>t>>s>>f;
		int a = MAP[s];
		int b = MAP[f];
		if(t == 1) {
			if(par[a] == par[b]) {
				cout<<"YES"<<endl;
				continue;
			}
			if(en[a] != -1) {
				int p = en[a];
				if(*cc[p].lower_bound(b) == b) {
					cout<<"NO"<<endl;
					continue;
				}
			}
			join(a,b);
			cout<<"YES"<<endl;
		}
		else {
			if(en[par[a]] == par[b]) {
				cout<<"YES"<<endl;
				continue;
			}
			if(par[a] == par[b]) {
				cout<<"NO"<<endl;
				continue;
			}
			disjoin(a,b);
			cout<<"YES"<<endl;
		}
	}
	for(int i = 1 ; i <= q ; i++) {
		string s,f;
		cin>>s>>f;
		int a = MAP[s];
		int b = MAP[f];
		if(par[a] == par[b])
			cout<<1<<endl;
		else if(en[par[a]] == par[b])
			cout<<2<<endl;
		else
			cout<<3<<endl;
	}

}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <iomanip>
#include <queue>
#include <deque>
#include <set>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <string>

using namespace std;

typedef long long ll;

const int MAX_N = 1e5+10;
const ll INF = 1e18;
const ll MOD = 1e9+7;

int n,m,q,par[MAX_N],en[MAX_N];
map<string,int>MAP;
set<int>cc[MAX_N];

void join(int x,int y) {
    x = par[x];
    y = par[y];

    if(cc[y].size() > cc[x].size()) swap(x,y);
    while(cc[y].size() > 0) {
    	int node = *cc[y].begin();
    	cc[y].erase(cc[y].begin());
    	par[node] = x;
    	cc[x].insert(node);
    }
    cc[y].clear();

    int xx = en[x];
    int yy = en[y];
    if(xx == -1) {
    	en[x] = yy;
    	return;
    }
    if(yy == -1) {
    	en[x] = xx;
    	return;
    }

    if(cc[yy].size() > cc[xx].size()) swap(xx,yy);
    while(cc[yy].size() > 0) {
    	int node = *cc[yy].begin();
    	cc[yy].erase(cc[yy].begin());
    	par[node] = x;
    	cc[xx].insert(node);
    }
    cc[yy].clear();

    en[x] = xx;
}

void disjoin(int x,int y) {
    x = par[x];
    y = par[y];
    int xx = en[x];
    int yy = en[y];

    if(yy != -1) {
    	if(cc[yy].size() > cc[x].size()) swap(x,yy);
	    while(cc[yy].size() > 0) {
	    	int node = *cc[yy].begin();
	    	cc[yy].erase(cc[yy].begin());
	    	par[node] = x;
	    	cc[x].insert(node);
    	}
    	cc[yy].clear();
    }

     if(xx != -1) {
    	if(cc[xx].size() > cc[y].size()) swap(xx,y);
	    while(cc[xx].size() > 0) {
	    	int node = *cc[xx].begin();
	    	cc[xx].erase(cc[xx].begin());
	    	par[node] = y;
	    	cc[y].insert(node);
    	}
    	cc[xx].clear();
    }
    en[x] = y;
    en[y] = x;
}

void kruskal() {
    for(int i = 1 ; i <= n ; i++) {
        par[i] = i;
        cc[i].insert(i);
        en[i] = -1;
    }
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>q;

	for(int i = 1 ; i <= n ; i++) {
		string s;
		cin>>s;
		MAP[s] = i;
	}
	kruskal();
	for(int i = 1 ; i <= m ; i++) {
		int t;
		string s,f;
		cin>>t>>s>>f;
		int a = MAP[s];
		int b = MAP[f];
		if(t == 1) {
			if(par[a] == par[b]) {
				cout<<"YES"<<endl;
				continue;
			}
			if(en[a] != -1) {
				int p = en[a];
				if(*cc[p].lower_bound(b) == b) {
					cout<<"NO"<<endl;
					continue;
				}
			}
			join(a,b);
			cout<<"YES"<<endl;
		}
		else {
			if(en[par[a]] == par[b]) {
				cout<<"YES"<<endl;
				continue;
			}
			if(par[a] == par[b]) {
				cout<<"NO"<<endl;
				continue;
			}
			disjoin(a,b);
			cout<<"YES"<<endl;
		}
	}
	for(int i = 1 ; i <= q ; i++) {
		string s,f;
		cin>>s>>f;
		int a = MAP[s];
		int b = MAP[f];
		if(par[a] == par[b])
			cout<<1<<endl;
		else if(en[par[a]] == par[b])
			cout<<2<<endl;
		else
			cout<<3<<endl;
	}

}


#include <bits/stdc++.h>
#define MAX_N 100100
using namespace std;

#define ll long long
#define ull unsigned long long
#define ii pair<int,int>
#define iii pair<ii, int>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ep emplace_back
#define sz(a) (int) a.size()
#define cl(a) a.clear()

#define vi vector<int>
#define vii vector<ii>

#define LOWBIT(x) ( (x) & -(x) )

#define FOR(x,a,b) for (int x=a;x<=b;x++)
#define FOD(x,a,b) for (int x=a;x>=b;x--)
#define REP(x,a,b) for (int x=a;x<b;x++)
#define RED(x,a,b) for (int x=a;x>b;x--)

const int MAX = 1e5 + 10;
const int MAXN = 1e4 + 10;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double pi = acos(-1.0);
const double eps = 1e-6;

int dx[] = {0 , -1 , 0 , 1};
int dy[] = {1 , 0 , -1 , 0};

struct edge
{
    int u , v , c;
};

int n , m , q;
vii V[MAX_N];
map <string , int> mymap;
edge a[MAX_N];
int lab[MAX_N];

class DSU
{
    private:
    int ro[MAX_N] , ra[MAX_N];

    public:
    void init(int n)
    {
        FOR(i , 0 , n)
        {
            ro[i] = i;
            ra[i] = 1;
        }
    }

    int findRoot(int i)
    {
        return (ro[i] == i ? i : (ro[i] = findRoot(ro[i])));
    }

    int isSameSet(int x , int y)
    {
        return (findRoot(x) == findRoot(y));
    }

    void unionSet(int x , int y)
    {
        if (!isSameSet(x , y))
        {
            int u = findRoot(x);
            int v = findRoot(y);

            if (ra[u] > ra[v]) ro[v] = u;
            else
            {
                ro[u] = v;
                if (ra[u] == ra[v]) ra[v]++;
            }
        }
    }
};

DSU dsu;

void BFS(int t)
{
    lab[t] = 0;
    queue <int> myqueue;
    bool mark[MAX_N];

    //FOR(i , 1 , n) mark[i] = false;

    myqueue.push(t);

    while (!myqueue.empty())
    {
        int v = myqueue.front();

        myqueue.pop();

        mark[v] = true;

        REP(i , 0 , V[v].size())
        {
            ii tmp = V[v][i];

            int u = tmp.fi;
            int c = tmp.se;

            if (!mark[u])
            {
                lab[u] = lab[v] ^ c;
                myqueue.push(u);
                dsu.unionSet(u , v);
            }
        }
    }
}

int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);

    //freopen("input.txt", "r" , stdin);

    cin >> n >> m >> q;

    FOR(i , 1 , n) lab[i] = -1;

    dsu.init(n);

    FOR(i , 1 , n)
    {
        string s;
        cin >> s;

        mymap[s] = i;
    }

    FOR(i , 1 , m)
    {
        string uu , vv;
        int t;

        cin >> t >> uu >> vv;

        a[i].c = t - 1;
        int u = mymap[uu];
        int v = mymap[vv];

        a[i].u = u;
        a[i].v = v;

        V[u].pb(mp(v , t - 1));
        V[v].pb(mp(u , t - 1));
    }

    FOR(i , 1 , n)
        if (lab[i] == -1) BFS(i);

    FOR(i , 1 , m)
    {
        int u = a[i].u;
        int v = a[i].v;
        int c = a[i].c;

        //cout << u << ' ' << v << ' ' << c << ' ' << lab[u] << ' ' << lab[v] << endl;

        if (lab[u] ^ lab[v] == c) cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    while (q--)
    {
        string uu , vv;

        cin >> uu >> vv;

        int u = mymap[uu];
        int v = mymap[vv];

        if (!dsu.isSameSet(u , v)) cout << 3;
        else cout << (lab[u] == lab[v] ? 1 : 2);

        cout << endl;
    }

	return 0;
}


#include <bits/stdc++.h>
#define MAX_N 100100
using namespace std;

#define ll long long
#define ull unsigned long long
#define ii pair<int,int>
#define iii pair<ii, int>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ep emplace_back
#define sz(a) (int) a.size()
#define cl(a) a.clear()

#define vi vector<int>
#define vii vector<ii>

#define LOWBIT(x) ( (x) & -(x) )

#define FOR(x,a,b) for (int x=a;x<=b;x++)
#define FOD(x,a,b) for (int x=a;x>=b;x--)
#define REP(x,a,b) for (int x=a;x<b;x++)
#define RED(x,a,b) for (int x=a;x>b;x--)

const int MAX = 1e5 + 10;
const int MAXN = 1e4 + 10;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double pi = acos(-1.0);
const double eps = 1e-6;

int dx[] = {0 , -1 , 0 , 1};
int dy[] = {1 , 0 , -1 , 0};

struct edge
{
    int u , v , c;
};

int n , m , q;
vii V[MAX_N];
map <string , int> mymap;
edge a[MAX_N];
int lab[MAX_N];
bool mark[MAX_N];

class DSU
{
    private:
    int ro[MAX_N] , ra[MAX_N];

    public:
    void init(int n)
    {
        FOR(i , 0 , n)
        {
            ro[i] = i;
            ra[i] = 1;
        }
    }

    int findRoot(int i)
    {
        return (ro[i] == i ? i : (ro[i] = findRoot(ro[i])));
    }

    int isSameSet(int x , int y)
    {
        return (findRoot(x) == findRoot(y));
    }

    void unionSet(int x , int y)
    {
        if (!isSameSet(x , y))
        {
            int u = findRoot(x);
            int v = findRoot(y);

            if (ra[u] > ra[v]) ro[v] = u;
            else
            {
                ro[u] = v;
                if (ra[u] == ra[v]) ra[v]++;
            }
        }
    }
};

DSU dsu;

void BFS(int t)
{
    lab[t] = 0;
    queue <int> myqueue;

    //FOR(i , 1 , n) mark[i] = false;

    myqueue.push(t);

    while (!myqueue.empty())
    {
        int v = myqueue.front();

        myqueue.pop();

        mark[v] = true;

        REP(i , 0 , V[v].size())
        {
            ii tmp = V[v][i];

            int u = tmp.fi;
            int c = tmp.se;

            if (!mark[u])
            {
                lab[u] = lab[v] ^ c;
                myqueue.push(u);
                dsu.unionSet(u , v);
            }
        }
    }
}

int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);

    //freopen("input.txt", "r" , stdin);

    cin >> n >> m >> q;

    FOR(i , 1 , n) lab[i] = -1;

    dsu.init(n);

    FOR(i , 1 , n)
    {
        string s;
        cin >> s;

        mymap[s] = i;
    }

    FOR(i , 1 , m)
    {
        string uu , vv;
        int t;

        cin >> t >> uu >> vv;

        a[i].c = t - 1;
        int u = mymap[uu];
        int v = mymap[vv];

        a[i].u = u;
        a[i].v = v;

        V[u].pb(mp(v , t - 1));
        V[v].pb(mp(u , t - 1));
    }

    FOR(i , 1 , n)
        if (!mark[i]) BFS(i);

    FOR(i , 1 , m)
    {
        int u = a[i].u;
        int v = a[i].v;
        int c = a[i].c;

        //cout << u << ' ' << v << ' ' << c << ' ' << lab[u] << ' ' << lab[v] << endl;

        if (lab[u] ^ lab[v] == c) cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    while (q--)
    {
        string uu , vv;

        cin >> uu >> vv;

        int u = mymap[uu];
        int v = mymap[vv];

        if (!dsu.isSameSet(u , v)) cout << 3;
        else cout << (lab[u] == lab[v] ? 1 : 2);

        cout << endl;
    }

	return 0;
}


#include <bits/stdc++.h>
#define MAX_N 100100
using namespace std;

#define ll long long
#define ull unsigned long long
#define ii pair<int,int>
#define iii pair<ii, int>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ep emplace_back
#define sz(a) (int) a.size()
#define cl(a) a.clear()

#define vi vector<int>
#define vii vector<ii>

#define LOWBIT(x) ( (x) & -(x) )

#define FOR(x,a,b) for (int x=a;x<=b;x++)
#define FOD(x,a,b) for (int x=a;x>=b;x--)
#define REP(x,a,b) for (int x=a;x<b;x++)
#define RED(x,a,b) for (int x=a;x>b;x--)

const int MAX = 1e5 + 10;
const int MAXN = 1e4 + 10;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double pi = acos(-1.0);
const double eps = 1e-6;

int dx[] = {0 , -1 , 0 , 1};
int dy[] = {1 , 0 , -1 , 0};

struct edge
{
    int u , v , c;
};

int n , m , q;
vii V[MAX_N];
map <string , int> mymap;
edge a[MAX_N];
int lab[MAX_N];
int mark[MAX_N];
int key = 0;
int p[MAX_N];

class DSU
{
    private:
    int ro[MAX_N] , ra[MAX_N];

    public:
    void init(int n)
    {
        FOR(i , 0 , n)
        {
            ro[i] = i;
            ra[i] = 1;
        }
    }

    int findRoot(int i)
    {
        return (ro[i] == i ? i : (ro[i] = findRoot(ro[i])));
    }

    int isSameSet(int x , int y)
    {
        return (findRoot(x) == findRoot(y));
    }

    void unionSet(int x , int y)
    {
        if (!isSameSet(x , y))
        {
            int u = findRoot(x);
            int v = findRoot(y);

            if (ra[u] > ra[v]) ro[v] = u;
            else
            {
                ro[u] = v;
                if (ra[u] == ra[v]) ra[v]++;
            }
        }
    }
};

DSU dsu;

void BFS(int t)
{
    lab[t] = 0;
    queue <int> myqueue = queue <int> ();
    ++key;
    mark[t] = key;

    //FOR(i , 1 , n) mark[i] = false;

    myqueue.push(t);

    while (!myqueue.empty())
    {
        int v = myqueue.front();

        myqueue.pop();

        REP(i , 0 , V[v].size())
        {
            ii tmp = V[v][i];

            int u = tmp.fi;
            int c = tmp.se;

            if (mark[u]) continue;

            lab[u] = lab[v] ^ c;
            myqueue.push(u);
            mark[u] = key;
        }
    }
}

int findRoot(int u)
{
	if (p[u] == -1) return u;
	return p[u] = findRoot(p[u]);
}

int connect(int u, int v)
{
	u = findRoot(u);
	v = findRoot(v);
	if (u == v) return 0;
	p[u] = v;
	return 1;
}

int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);

    //freopen("input.txt", "r" , stdin);

    cin >> n >> m >> q;

    FOR(i , 0 , n) p[i] = -1;

    FOR(i , 1 , n) lab[i] = -1;

    dsu.init(n);

    FOR(i , 1 , n)
    {
        string s;
        cin >> s;

        mymap[s] = i;
    }

    FOR(i , 1 , m)
    {
        string uu , vv;
        int t;

        cin >> t >> uu >> vv;

        a[i].c = t - 1;
        int u = mymap[uu];
        int v = mymap[vv];

        a[i].u = u;
        a[i].v = v;

        if (connect(u , v))
        {
            V[u].pb(mp(v , t - 1));
            V[v].pb(mp(u , t - 1));
        }
    }

    FOR(i , 1 , n) if (!mark[i]) BFS(i);

    FOR(i , 1 , m)
    {
        int u = a[i].u;
        int v = a[i].v;
        int c = a[i].c;

        //cout << u << ' ' << v << ' ' << c << ' ' << lab[u] << ' ' << lab[v] << endl;

        if (lab[u] ^ lab[v] == c) cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    while (q--)
    {
        string uu , vv;

        cin >> uu >> vv;

        int u = mymap[uu];
        int v = mymap[vv];

        if (mark[u] != mark[v]) cout << 3;
        else cout << (lab[u] == lab[v] ? 1 : 2);

        cout << endl;
    }

	return 0;
}


#include <bits/stdc++.h>
#define MAX_N 100100
using namespace std;

#define ll long long
#define ull unsigned long long
#define ii pair<int,int>
#define iii pair<ii, int>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ep emplace_back
#define sz(a) (int) a.size()
#define cl(a) a.clear()

#define vi vector<int>
#define vii vector<ii>

#define LOWBIT(x) ( (x) & -(x) )

#define FOR(x,a,b) for (int x=a;x<=b;x++)
#define FOD(x,a,b) for (int x=a;x>=b;x--)
#define REP(x,a,b) for (int x=a;x<b;x++)
#define RED(x,a,b) for (int x=a;x>b;x--)

const int MAX = 1e5 + 10;
const int MAXN = 1e4 + 10;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double pi = acos(-1.0);
const double eps = 1e-6;

int dx[] = {0 , -1 , 0 , 1};
int dy[] = {1 , 0 , -1 , 0};

struct edge
{
    int u , v , c;
};

int n , m , q;
vii V[MAX_N];
map <string , int> mymap;
edge a[MAX_N];
int lab[MAX_N];

class DSU
{
    private:
    int ro[MAX_N] , ra[MAX_N];

    public:
    void init(int n)
    {
        FOR(i , 0 , n)
        {
            ro[i] = i;
            ra[i] = 1;
        }
    }

    int findRoot(int i)
    {
        return (ro[i] == i ? i : (ro[i] = findRoot(ro[i])));
    }

    int isSameSet(int x , int y)
    {
        return (findRoot(x) == findRoot(y));
    }

    void unionSet(int x , int y)
    {
        if (!isSameSet(x , y))
        {
            int u = findRoot(x);
            int v = findRoot(y);

            if (ra[u] > ra[v]) ro[v] = u;
            else
            {
                ro[u] = v;
                if (ra[u] == ra[v]) ra[v]++;
            }
        }
    }
};

DSU dsu;

void BFS(int t)
{
    lab[t] = 0;
    queue <int> myqueue;
    bool mark[MAX_N];

    //FOR(i , 1 , n) mark[i] = false;

    myqueue.push(t);

    while (!myqueue.empty())
    {
        int v = myqueue.front();

        myqueue.pop();

        mark[v] = true;

        REP(i , 0 , V[v].size())
        {
            ii tmp = V[v][i];

            int u = tmp.fi;
            int c = tmp.se;

            if (lab[u] == -1)
            {
                lab[u] = lab[v] ^ c;
                myqueue.push(u);
                dsu.unionSet(u , v);
            }
        }
    }
}

int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);

    //freopen("input.txt", "r" , stdin);

    cin >> n >> m >> q;

    FOR(i , 1 , n) lab[i] = -1;

    dsu.init(n);

    FOR(i , 1 , n)
    {
        string s;
        cin >> s;

        mymap[s] = i;
    }

    FOR(i , 1 , m)
    {
        string uu , vv;
        int t;

        cin >> t >> uu >> vv;

        a[i].c = t - 1;
        int u = mymap[uu];
        int v = mymap[vv];

        a[i].u = u;
        a[i].v = v;

        V[u].pb(mp(v , t - 1));
        V[v].pb(mp(u , t - 1));
    }

    FOR(i , 1 , n)
        if (lab[i] == -1) BFS(i);

    FOR(i , 1 , m)
    {
        int u = a[i].u;
        int v = a[i].v;
        int c = a[i].c;

        cout << u << ' ' << v << ' ' << c << ' ' << lab[u] << ' ' << lab[v] << endl;

        if (lab[u] ^ lab[v] == c) cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    while (q--)
    {
        string uu , vv;

        cin >> uu >> vv;

        int u = mymap[uu];
        int v = mymap[vv];

        if (!dsu.isSameSet(u , v)) cout << 3;
        else cout << (lab[u] == lab[v] ? 1 : 2);

        cout << 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[1200005]={};
int find(int x){
    return vis[x]==x?x:vis[x]=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;
                vis[tmp1]=tmp4;
                vis[tmp3]=tmp2;
            }
            else{
               if(tmp1==tmp4){
                    cout<<"NO"<<endl;
                    con;
                }
                if(tmp3==tmp2){
                    cout<<"NO"<<endl;
                    con;
                }
                cout<<"YES"<<endl;
                vis[tmp1]=tmp2;
                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>
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()
{
    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];
            if(z==1){
                if(find(t1*2)==find(t2*2-1)){
                    cout<<"NO"<<endl;
                    con;
                }
                if(find(t1*2-1)==find(t2*2)){
                    cout<<"NO"<<endl;
                    con;
                }
                cout<<"YES"<<endl;
                vis[find(t1*2)]=find(t2*2);
                vis[find(t1*2-1)]=find(t2*2-1);
            }
            else{
               if(find(t1*2)==find(t2*2)){
                    cout<<"NO"<<endl;
                    con;
                }
                if(find(t1*2-1)==find(t2*2-1)){
                    cout<<"NO"<<endl;
                    con;
                }
                cout<<"YES"<<endl;
                vis[find(t1*2)]=find(t2*2-1);
                vis[find(t1*2-1)]=find(t2*2);
            }
        }
        for(int i=0;i<c;i++){
            string x,y;
            cin>>x>>y;
            int t1=num[x],t2=num[y];
            if( find(t1*2)==find(t2*2)||find(t1*2-1)==find(t2*2-1) ){
                cout<<1<<endl;
            }
            else if( find(t1*2-1)==find(t2*2)||find(t1*2)==find(t2*2-1) ){
                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];
            if(z==1){
                if(find(t1*2)==find(t2*2-1)){
                    cout<<"NO"<<endl;
                    con;
                }
                if(find(t1*2-1)==find(t2*2)){
                    cout<<"NO"<<endl;
                    con;
                }
                cout<<"YES"<<endl;
                vis[find(t1*2)]=find(t2*2);
                vis[find(t1*2-1)]=find(t2*2-1);
            }
            else{
               if(find(t1*2)==find(t2*2)){
                    cout<<"NO"<<endl;
                    con;
                }
                if(find(t1*2-1)==find(t2*2-1)){
                    cout<<"NO"<<endl;
                    con;
                }
                cout<<"YES"<<endl;
                vis[find(t1*2)]=find(t2*2-1);
                vis[find(t1*2-1)]=find(t2*2);
            }
        }
        for(int i=0;i<c;i++){
            string x,y;
            cin>>x>>y;
            int t1=num[x],t2=num[y];
            if( find(t1*2)==find(t2*2)||find(t1*2-1)==find(t2*2-1) ){
                cout<<1<<endl;
            }
            else if( find(t1*2-1)==find(t2*2)||find(t1*2)==find(t2*2-1) ){
                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[1200005]={};
int find(int a){
	if(vis[a]!=a)vis[a]=find(vis[a]);
	return vis[a];
}
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[1200005]={};
int find(int x){
    if(x!=vis[x]){
        return find(vis[x]);
    }
    else return 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[1200005]={};
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;
}