#include <bits/stdc++.h>
using namespace std;
void IOS() {
  ios::sync_with_stdio(false);
  cout.precision(10);
  cout << fixed;
}
const long long MOD = 1e9 + 7;
const long long mx = 1e5 + 2;
long long i, j, k;
struct dsu {
  long long n;
  vector<long long> sizes, marks, cols;
  vector<vector<pair<long long, long long>>> graph;
  void init(long long rn) {
    n = rn;
    sizes = vector<long long>(n);
    cols = vector<long long>(n);
    fill(sizes.begin(), sizes.end(), 1);
    marks = vector<long long>(n);
    for (long long i = 0; i < n; i++) marks[i] = i;
    graph = vector<vector<pair<long long, long long>>>(n);
  }
  void mark(long long m, long long node, long long c) {
    if (marks[node] == m) return;
    marks[node] = m;
    cols[node] = c;
    for (pair<long long, long long> i : graph[node])
      mark(m, i.first, c ^ i.second);
  }
  bool merge(long long a, long long b, long long c) {
    if (marks[a] == marks[b]) {
      return ((cols[a] ^ cols[b]) == c);
    }
    graph[a].push_back({b, c});
    graph[b].push_back({a, c});
    if (sizes[marks[a]] > sizes[marks[b]]) swap(a, b);
    sizes[marks[b]] += sizes[marks[a]];
    sizes[marks[a]] = 0;
    mark(marks[b], a, cols[b] ^ c);
    return 1;
  }
  long long find(long long n) { return marks[n]; }
};
dsu d;
long long n, m, q, l, r, x, y, z;
map<string, long long> mp;
string s, t;
void solve(long long tc = 0) {
  cin >> n >> m >> q;
  d.init(n);
  for (i = 0; i < n; i++) {
    cin >> s;
    mp[s] = i;
  }
  for (i = 0; i < m; i++) {
    cin >> z >> s >> t;
    x = mp[s];
    y = mp[t];
    bool r = d.merge(x, y, --z);
    if (r)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  for (i = 0; i < q; i++) {
    cin >> s >> t;
    x = mp[s];
    y = mp[t];
    if (d.marks[x] == d.marks[y]) {
      cout << ((d.cols[x] ^ d.cols[y]) + 1) << '\n';
    } else {
      cout << 3 << '\n';
    }
  }
}
int32_t main() {
  IOS();
  solve();
  return 0;
}
