#include <bits/stdc++.h>
using namespace std;
const double pi = acos((double)(-1));
const int maxn = 100010;
const int mod = 1e9 + 7;
int moven2[10][5] = {{1, 0, 0},  {-1, 0, 0}, {0, 1, 0},
                     {0, -1, 0}, {0, 0, 1},  {0, 0, -1}};
int moven1[10][5] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int n, m, q, f[2 * maxn];
map<string, int> mp;
string a, b;
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
void Union(int x, int y) {
  int fx = find(x);
  int fy = find(y);
  f[fx] = fy;
}
int main() {
  cin >> n >> m >> q;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    mp[a] = i;
  }
  for (int i = 1; i <= 2 * n; i++) f[i] = i;
  for (int i = 1, t; i <= m; i++) {
    cin >> t >> a >> b;
    int x = mp[a];
    int y = mp[b];
    if (t == 1) {
      if (find(x) == find(y + n) || find(y) == find(x + n))
        cout << "NO"
             << "\n";
      else {
        cout << "YES"
             << "\n";
        Union(x, y);
        Union(x + n, y + n);
      }
    } else {
      if (find(x) == find(y) || find(x + n) == find(y + n))
        cout << "NO"
             << "\n";
      else {
        cout << "YES"
             << "\n";
        Union(x + n, y);
        Union(x, y + n);
      }
    }
  }
  for (int i = 1; i <= q; i++) {
    cin >> a >> b;
    int x = mp[a];
    int y = mp[b];
    if (find(x) == find(y) || find(x + n) == find(y + n))
      cout << 1 << "\n";
    else if (find(x + n) == find(y) || find(x) == find(y + n))
      cout << 2 << "\n";
    else
      cout << 3 << "\n";
  }
  return 0;
}
