#include <bits/stdc++.h>
using namespace std;
int f[200000];
int relation[200000];
int Find(int x) {
  int a;
  if (f[x] == x) return x;
  a = f[x];
  f[x] = Find(f[x]);
  relation[x] = (relation[x] + relation[a]) % 2;
  return f[x];
}
int main() {
  int n, m, q;
  string s[200000];
  string s1, s2;
  map<string, int> mp;
  cin >> n >> m >> q;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    mp[s[i]] = i;
    f[i] = i;
    relation[i] = 0;
  }
  for (int i = 1; i <= m; i++) {
    int x, y, z, a, b;
    cin >> z >> s1 >> s2;
    z = z - 1;
    x = mp[s1];
    a = Find(x);
    y = mp[s2];
    b = Find(y);
    if (a != b) {
      f[b] = a;
      relation[b] = (z + relation[x] - relation[y]) % 2;
      cout << "YES" << endl;
    } else {
      int temp = (relation[x] - relation[y] + 2) % 2;
      if (temp != z)
        cout << "NO" << endl;
      else
        cout << "YES" << endl;
    }
  }
  for (int i = 1; i <= q; i++) {
    cin >> s1 >> s2;
    int x, y;
    x = mp[s1], y = mp[s2];
    if (Find(x) != Find(y))
      cout << "3" << endl;
    else {
      int temp = (relation[x] - relation[y] + 2) % 2;
      cout << temp + 1 << endl;
    }
  }
  return 0;
}
