#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 5;
const int offset = (int)1e5 + 1;
unordered_map<string, int> m;
int parent[N];
int find_parent(int v) {
  if (v != parent[v]) {
    parent[v] = find_parent(parent[v]);
  }
  return parent[v];
}
void disjoint_set_union(int u, int v) {
  parent[find_parent(u)] = find_parent(v);
}
int main() {
  int n, M, q;
  cin >> n >> M >> q;
  int z = 1;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    m[s] = z++;
  }
  for (int i = 1; i < z; i++) {
    parent[i] = i;
    parent[i + offset] = i + offset;
  }
  for (int i = 0; i < M; i++) {
    int t;
    string X, Y;
    cin >> t >> X >> Y;
    int x = m[X];
    int y = m[Y];
    bool ok = false;
    if (t == 1) {
      if (find_parent(x) != find_parent(y + offset) &&
          find_parent(y) != find_parent(x + offset)) {
        disjoint_set_union(x, y);
        disjoint_set_union(x + offset, y + offset);
        ok = true;
      }
    } else {
      if (find_parent(x) != find_parent(y) &&
          find_parent(x + offset) != find_parent(y + offset)) {
        disjoint_set_union(x, y + offset);
        disjoint_set_union(y, x + offset);
        ok = true;
      }
    }
    if (ok)
      puts("YES");
    else
      puts("NO");
  }
  for (int i = 0; i < q; i++) {
    string X, Y;
    cin >> X >> Y;
    int x = m[X];
    int y = m[Y];
    if (find_parent(x) == find_parent(y))
      puts("1");
    else if (find_parent(x) == find_parent(y + offset))
      puts("2");
    else
      puts("3");
  }
}
