#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct dsu {
  int n, par[N];
  void init(int _n) {
    n = _n;
    for (int i = 1; i <= n; i++) par[i] = i;
  }
  int Find(int at) { return par[at] == at ? at : par[at] = Find(par[at]); }
  void Union(int a, int b) {
    a = Find(a), b = Find(b);
    if (a != b) par[b] = a;
  }
};
dsu ds;
int n, m, q, en[N];
string name[N];
map<string, int> mp;
bool isAA(int a, int b) {
  if (ds.Find(a) == ds.Find(b))
    return true;
  else
    return false;
}
bool isBB(int a, int b) {
  a = ds.Find(a), b = ds.Find(b);
  if (ds.Find(en[a]) == ds.Find(b)) return true;
  if (ds.Find(en[b]) == ds.Find(a)) return true;
  return false;
}
void makeAA(int a, int b) {
  a = ds.Find(a), b = ds.Find(b);
  if (en[a] && en[b]) ds.Union(en[a], en[b]);
  if (!en[a]) en[a] = ds.Find(en[b]);
  if (!en[b]) en[b] = ds.Find(en[a]);
  ds.Union(a, b);
}
void makeBB(int a, int b) {
  a = ds.Find(a), b = ds.Find(b);
  if (!en[a])
    en[a] = b;
  else
    ds.Union(en[a], b);
  if (!en[b])
    en[b] = a;
  else
    ds.Union(en[b], a);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m >> q;
  for (int i = 1; i <= n; i++) {
    cin >> name[i];
    mp[name[i]] = i;
  }
  string a, b;
  int t, x, y;
  ds.init(n);
  for (int i = 1; i <= m; i++) {
    cin >> t >> a >> b;
    x = mp[a], y = mp[b];
    if (t == 1) {
      if (isBB(x, y))
        cout << "NO\n";
      else {
        makeAA(x, y);
        cout << "YES\n";
      }
    } else {
      if (isAA(x, y))
        cout << "NO\n";
      else {
        makeBB(x, y);
        cout << "YES\n";
      }
    }
  }
  for (int i = 1; i <= q; i++) {
    cin >> a >> b;
    x = mp[a], y = mp[b];
    if (isAA(x, y))
      cout << "1\n";
    else if (isBB(x, y))
      cout << "2\n";
    else
      cout << "3\n";
  }
  return 0;
}
