#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int N = 100100;
vector<pair<int, int> > g[N];
int T[N];
int xr[N];
int valid[N], ind1[N], ind2[N];
map<string, int> index228;
struct DSU {
  vector<int> p, rg;
  int n;
  DSU(int _n) {
    n = _n;
    p.resize(n + 228);
    rg.resize(n + 228);
  }
  inline void build() {
    for (int i = 1; i <= n; ++i) {
      p[i] = i;
      rg[i] = 1;
    }
  }
  int get_root(int v) {
    if (v == p[v]) {
      return v;
    }
    p[v] = get_root(p[v]);
    return p[v];
  }
  inline void join(int v1, int v2) {
    v1 = get_root(v1);
    v2 = get_root(v2);
    if (v1 != v2) {
      if (rg[v1] < rg[v2]) {
        swap(v1, v2);
      }
      if (rg[v1] == rg[v2]) {
        ++rg[v1];
      }
      p[v2] = p[v1];
    }
  }
  inline bool same(int v1, int v2) { return get_root(v1) == get_root(v2); }
};
int n, m, q;
bool used[N];
void dfs(int v, int cur = 0) {
  used[v] = true;
  xr[v] = cur;
  for (int i = 0; i < (int)g[v].size(); ++i) {
    int to = g[v][i].first;
    int val = g[v][i].second;
    if (used[to]) continue;
    dfs(to, cur ^ val);
  }
}
inline void pre() {
  for (int i = 1; i <= n; ++i) {
    if (!used[i]) {
      dfs(i);
    }
  }
}
inline int get(int u, int v) { return xr[u] ^ xr[v]; }
int main() {
  scanf("%d %d %d", &n, &m, &q);
  for (int i = 1; i <= n; ++i) {
    string s;
    cin >> s;
    index228[s] = i;
  }
  DSU dsu = DSU(n);
  dsu.build();
  for (int i = 1; i <= m; ++i) {
    int t;
    scanf("%d", &t);
    T[i] = t - 1;
    string w1, w2;
    cin >> w1 >> w2;
    int fir = index228[w1], sec = index228[w2];
    if (!dsu.same(fir, sec)) {
      valid[i] = 1;
      dsu.join(fir, sec);
      g[fir].push_back({sec, t - 1});
      g[sec].push_back({fir, t - 1});
    } else {
      valid[i] = 2;
      ind1[i] = fir;
      ind2[i] = sec;
    }
  }
  pre();
  for (int i = 1; i <= m; ++i) {
    if (valid[i] == 2) {
      int fir = ind1[i], sec = ind2[i];
      if (get(fir, sec) == T[i]) {
        valid[i] = 1;
      } else {
        valid[i] = 0;
      }
    }
    if (valid[i]) {
      puts("YES");
    } else {
      puts("NO");
    }
  }
  for (int i = 0; i < q; ++i) {
    string w1, w2;
    cin >> w1 >> w2;
    int fir = index228[w1], sec = index228[w2];
    if (!dsu.same(fir, sec)) {
      puts("3");
    } else {
      if (get(fir, sec) == 0) {
        puts("1");
      } else {
        puts("2");
      }
    }
  }
  return 0;
}
