#include <bits/stdc++.h>
using namespace std;
void rvi(vector<int> &v, int n) {
  v.clear();
  int temp;
  for (int i = 0; i < n; i++) {
    scanf("%d", &temp);
    v.push_back(temp);
  }
}
void rvll(vector<long long int> &v, int n) {
  v.clear();
  long long int temp;
  for (int i = 0; i < n; i++) {
    scanf("%lld", &temp);
    v.push_back(temp);
  }
}
struct subset {
  int parent;
  int rank;
  int opparent;
};
struct subset subsets[200000];
int find(int i) {
  if (subsets[i].parent != i) subsets[i].parent = find(subsets[i].parent);
  return subsets[i].parent;
}
void Union(int x, int y) {
  int xroot = find(x);
  int yroot = find(y);
  if (subsets[xroot].rank < subsets[yroot].rank)
    subsets[xroot].parent = yroot;
  else if (subsets[xroot].rank > subsets[yroot].rank)
    subsets[yroot].parent = xroot;
  else {
    subsets[yroot].parent = xroot;
    subsets[xroot].rank++;
  }
}
map<string, int> smap;
int main() {
  for (int i = 0; i <= 100005; i++) {
    subsets[i].parent = i;
    subsets[i].rank = 1;
    subsets[i].opparent = -1;
  }
  int n, m, q;
  scanf("%d", &n);
  scanf("%d", &m);
  scanf("%d", &q);
  string str;
  for (int i = 1; i <= n; i++) {
    cin >> str;
    smap[str] = i;
  }
  string str1, str2;
  int t1, t2;
  for (int i = 1; i <= m; i++) {
    int temp;
    scanf("%d", &temp);
    cin >> str1 >> str2;
    t1 = smap[str1];
    t2 = smap[str2];
    int x = find(t1);
    int y = find(t2);
    if (temp == 1) {
      if (x == y) {
        printf("YES\n");
      } else {
        if ((subsets[x].opparent == y) || (x == subsets[y].opparent)) {
          printf("NO\n");
        } else {
          printf("YES\n");
          int op1 = subsets[x].opparent;
          int op2 = subsets[y].opparent;
          Union(x, y);
          int p, q;
          if (op1 != -1 && op2 != -1) {
            Union(op1, op2);
            p = find(x);
            q = find(op1);
            subsets[p].opparent = q;
            subsets[q].opparent = p;
          } else if (op1 == -1 && op2 != -1) {
            p = find(x);
            subsets[p].opparent = op2;
            subsets[op2].opparent = p;
          } else if (op2 == -1 && op1 != -1) {
            p = find(y);
            subsets[p].opparent = op1;
            subsets[op1].opparent = p;
          }
        }
      }
    } else {
      if (x == y) {
        printf("NO\n");
      } else {
        {
          printf("YES\n");
          int op1 = subsets[x].opparent;
          int op2 = subsets[y].opparent;
          int p, q;
          if (op1 != -1 && op2 != -1) {
            Union(op1, y);
            Union(op2, x);
            p = find(x);
            q = find(y);
            subsets[p].opparent = q;
            subsets[q].opparent = p;
          } else if (op1 == -1 && op2 != -1) {
            Union(op2, x);
            p = find(x);
            subsets[p].opparent = y;
            subsets[y].opparent = p;
          } else if (op2 == -1 && op1 != -1) {
            Union(op1, y);
            int p = find(y);
            subsets[p].opparent = x;
            subsets[x].opparent = p;
          } else {
            subsets[x].opparent = y;
            subsets[y].opparent = x;
          }
        }
      }
    }
  }
  while (q--) {
    cin >> str1 >> str2;
    t1 = smap[str1];
    t2 = smap[str2];
    int x = find(t1);
    int y = find(t2);
    if (x == y) {
      printf("1\n");
    } else if ((subsets[x].opparent == y) || (subsets[y].opparent == x)) {
      printf("2\n");
    } else {
      printf("3\n");
    }
  }
  return 0;
}
