#include <bits/stdc++.h>
using namespace std;
long long n, m, q;
string a[200000];
map<string, long long> ind;
long long sz[200000];
pair<long long, long long> p[200000];
long long find_set(long long v) {
  while (v != p[v].first) {
    v = p[v].first;
  }
  return v;
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> n >> m >> q;
  for (long long i = 1; i <= n; i++) {
    p[i] = {i, 0};
    sz[i] = 1;
    cin >> a[i];
    ind[a[i]] = i;
  }
  for (long long i = 1; i <= m; i++) {
    long long t;
    cin >> t;
    string x, y;
    cin >> x >> y;
    long long a = ind[x], b = ind[y];
    long long cnt = 0;
    while (p[a].first != a) {
      cnt += p[a].second;
      a = p[a].first;
    }
    while (p[b].first != b) {
      cnt += p[b].second;
      b = p[b].first;
    }
    if (a == b) {
      if ((t & 1) == (cnt & 1)) {
        cout << "NO\n";
      } else
        cout << "YES\n";
    } else {
      cout << "YES\n";
      if (sz[a] > sz[b]) {
        swap(a, b);
      }
      if (t == 1) {
        if (cnt & 1) {
          p[a] = {b, 1}, sz[b] += sz[a];
        } else
          p[a] = {b, 0}, sz[b] += sz[a];
      } else {
        if (cnt & 1) {
          p[a] = {b, 0};
        } else
          p[a] = {b, 1};
      }
    }
  }
  for (long long i = 1; i <= q; i++) {
    string x, y;
    cin >> x >> y;
    long long a = ind[x], b = ind[y];
    long long cnt = 0;
    while (a != p[a].first) {
      cnt += p[a].second;
      a = p[a].first;
    }
    while (b != p[b].first) {
      cnt += p[b].second;
      b = p[b].first;
    }
    if (a != b)
      cout << "3\n";
    else if (cnt & 1)
      cout << "2\n";
    else
      cout << "1\n";
  }
}
