#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int add(int a, int b) {
  long long x = a + b;
  if (x >= 1000000007) x -= 1000000007;
  if (x < 0) x += 1000000007;
  return x;
}
long long mul(long long a, long long b) { return (a * b) % 1000000007; }
long long pw(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return ans;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand_seed() {
  long long a = rng();
  return a;
}
vector<int> dsu[100002];
int n, m, q, tt[100002], rel[100002];
map<string, int> mp;
int Find(int nod) {
  if (tt[nod] == nod) return nod;
  return tt[nod] = Find(tt[nod]);
}
void Unite(int a, int b, int rx) {
  int x = Find(a);
  int y = Find(b);
  if (dsu[x].size() < dsu[y].size()) swap(x, y);
  bool flip = 0;
  if (rel[b] == rel[a] && rx == 1) flip = 1;
  if (rel[b] != rel[a] && rx == 0) flip = 1;
  for (int i = 0; i < dsu[y].size(); ++i) rel[dsu[y][i]] ^= flip;
  tt[y] = x;
  for (int i = 0; i < dsu[y].size(); ++i) {
    int vecin = dsu[y][i];
    dsu[x].push_back(vecin);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m >> q;
  for (int i = 1; i <= n; ++i) {
    string s;
    cin >> s;
    mp[s] = i;
  }
  for (int i = 1; i <= n; ++i) tt[i] = i, dsu[i].push_back(i);
  for (int i = 1; i <= m; ++i) {
    int tip;
    string a, b;
    cin >> tip >> a >> b;
    int x = mp[a];
    int y = mp[b];
    --tip;
    if (Find(x) == Find(y)) {
      if (tip == 0 && rel[x] != rel[y])
        cout << "NO\n";
      else if (tip == 1 && rel[x] == rel[y])
        cout << "NO\n";
      else
        cout << "YES\n";
    } else {
      cout << "YES\n";
      Unite(x, y, tip);
    }
  }
  for (int i = 1; i <= q; ++i) {
    string a, b;
    cin >> a >> b;
    int x = mp[a];
    int y = mp[b];
    if (Find(x) != Find(y))
      cout << "3\n";
    else if (rel[x] == rel[y])
      cout << "1\n";
    else
      cout << "2\n";
  }
  return 0;
}
