#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793238462643383279;
const long double EPS = 1e-6;
const long long INF = 1e9 + 7;
const long long MOD = INF;
const long long maxn = 5e5 + 2;
const long long HASH_MODS[] = {1000000007333, 1000000009367, 1000000075747,
                               1000000158923, 1000000203119};
map<string, int> mp;
int diff[maxn];
string a[maxn];
int p[maxn];
int _find(int v) {
  if (v == p[v]) return v;
  return p[v] = _find(p[v]);
}
void unit(int a, int b) {
  a = _find(a);
  b = _find(b);
  if (a != b) {
    p[b] = a;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m, q;
  cin >> n >> m >> q;
  for (int i = (1); i < (n + 1); ++i) {
    cin >> a[i];
    mp[a[i]] = i;
    p[i] = i;
  }
  for (int i = (0); i < (m); ++i) {
    int t;
    string x, y;
    cin >> t >> x >> y;
    int px = _find(mp[x]);
    int py = _find(mp[y]);
    if (t == 1) {
      if (diff[px] == py) {
        cout << "NO\n";
        continue;
      }
      cout << "YES\n";
      unit(px, py);
      if (diff[px] != diff[py]) {
        if (diff[px] && diff[py]) {
          unit(diff[px], diff[py]);
          diff[_find(px)] = _find(diff[px]);
          diff[_find(diff[px])] = _find(px);
        } else if (diff[px]) {
          diff[_find(px)] = diff[px];
          diff[diff[px]] = _find(px);
        } else if (diff[py]) {
          diff[_find(px)] = diff[py];
          diff[diff[py]] = _find(px);
        }
      } else
        diff[_find(px)] = diff[px];
    } else {
      if (px == py) {
        cout << "NO\n";
        continue;
      }
      cout << "YES\n";
      if (diff[px] != diff[py]) {
        if (diff[px] && diff[py]) {
          unit(px, diff[py]);
          unit(py, diff[px]);
          diff[_find(px)] = _find(py);
          diff[_find(py)] = _find(px);
        } else if (diff[px]) {
          unit(py, diff[px]);
          diff[px] = _find(py);
          diff[_find(py)] = px;
        } else if (diff[py]) {
          unit(px, diff[py]);
          diff[py] = _find(px);
          diff[_find(px)] = py;
        }
      } else {
        diff[px] = py;
        diff[py] = px;
      }
    }
  }
  for (int i = (0); i < (q); ++i) {
    string x, y;
    cin >> x >> y;
    int px = _find(mp[x]);
    int py = _find(mp[y]);
    if (px == py)
      cout << 1 << "\n";
    else if (diff[px] == py)
      cout << 2 << "\n";
    else
      cout << 3 << "\n";
  }
}
