#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   const int M = 1e9 + 7;   const int MOD = 998244353;   const double PI = 3.141592653589793238460;   const int bs = 1e9 + 7;   unsigned long long power(unsigned long long a, unsigned long long b) {     unsigned long long res = 1;     if (a == 0) return 0;     if (a == 1) return 1;     for (; b > 0; b >>= 1) {       if (b & 1) res = (res * a);       if (res > MOD) res %= MOD;       a = (a * a);       if (a > MOD) a = a % MOD;     }     return res;   }   bool isPrime[1000001];   vector<unsigned long long> prime;   void seive(int limit) {     isPrime[0] = isPrime[1] = 1;     for (int i = 2; i * i <= limit; i++) {       if (!isPrime[i])         for (int j = i * i; j <= limit; j += i) {           isPrime[j] = 1;         }     }     for (int i = 2; i <= limit; i++)       if (!isPrime[i]) prime.push_back(i);   }   map<string, int> m;   unsigned long long parent[100100], sz[100100];   vector<pair<unsigned long long, unsigned long long>> v[100010];   vector<pair<pair<unsigned long long, unsigned long long>,               pair<unsigned long long, unsigned long long>>>       rem;   int visited[100010], valid[100010], cum[100110];   int n, q1, q2;   int finds(int i) {     while (parent[i] != i) i = parent[i];     return i;   }   int unions(int x, int y) {     int xr = finds(x);     int yr = finds(y);     if (xr == yr) return 0;     if (sz[xr] > sz[yr])       parent[yr] = xr;     else if (sz[xr] < sz[yr])       parent[xr] = yr;     else {       sz[yr]++;       parent[xr] = yr;     }     return 1;   }   void dfs(int node, int pnode, int x) {     cum[node] = x;     visited[node] = 1;     for (int i = 0; i < v[node].size(); i++) {       if (!visited[v[node][i].first])         dfs(v[node][i].first, node, x ^ (v[node][i].second));     }   }   void process() {     for (int i = 0; i < n; i++)       if (!visited[i]) dfs(i, i, 0);     for (int i = 0; i < rem.size(); i++) {       int x = rem[i].first.first, y = rem[i].first.second;       int idx = rem[i].second.first, t = rem[i].second.second;       if (cum[x] ^ cum[y] != t)         valid[idx] = 0;       else         valid[idx] = 1;     }   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0);     int tt = 1;     while (tt--) {       cin >> n >> q1 >> q2;       for (int i = 0; i < n; i++) {         string s;         cin >> s;         m[s] = i;         parent[i] = i;         sz[i] = 0;       }       for (int i = 0; i < q1; i++) {         int t;         cin >> t;         string a, b;         cin >> a >> b;         int x = m[a], y = m[b];         if (unions(x, y)) {           v[x].push_back({y, t - 1});           v[y].push_back({x, t - 1});           valid[i] = 1;         } else           rem.push_back({{x, y}, {i, t - 1}});       }       process();       for (int i = 0; i < q1; i++) {         if (valid[i])           cout <<  YES                 <<   n ;         else           cout <<  NO                 <<   n ;       }       for (int i = 0; i < q2; i++) {         string a, b;         cin >> a >> b;         int x = m[a], y = m[b];         if (finds(x) != finds(y))           cout << 3 <<   n ;         else           cout << (cum[x] ^ cum[y]) + 1 <<   n ;       }     }   }