#include <bits/stdc++.h>
using namespace std;
struct Gate {
  int kind, x, y;
  Gate() {}
  Gate(int a, int b, int c) : kind(a), x(b), y(c) {}
};
Gate a[55];
bool in[55];
int calc(Gate t, int n) {
  memset(in, 0, sizeof(in));
  in[a[t.x].x] = in[a[t.x].y] = 1;
  in[a[t.y].x] = in[a[t.y].y] = 1;
  int cnt = 0;
  for (int i = 1; i <= n; i++) cnt += in[i];
  int x = t.kind, y = a[t.x].kind, z = a[t.y].kind;
  if (cnt == 2) {
    if (x == 1 && y == 1 && z == 3) return 1;
    if (x == 1 && y == 3 && z == 1) return 1;
    if (x == 3 && y == 1 && z == 3) return 3;
    if (x == 3 && y == 3 && z == 1) return 3;
    if (x == 1 && y == 2 && z == 4) return 1;
    if (x == 1 && y == 4 && z == 2) return 1;
    if (x == 3 && y == 2 && z == 4) return 3;
    if (x == 3 && y == 4 && z == 2) return 3;
    if (x == 4 && y == 1 && z == 3) return 1;
    if (x == 4 && y == 3 && z == 1) return 1;
    if (x == 2 && y == 1 && z == 3) return 3;
    if (x == 2 && y == 3 && z == 1) return 3;
    if (x == 4 && y == 2 && z == 4) return 1;
    if (x == 4 && y == 4 && z == 2) return 1;
    if (x == 2 && y == 2 && z == 4) return 3;
    if (x == 2 && y == 4 && z == 2) return 3;
    if (x == 1 && y == 1 && z == 4) return 2;
    if (x == 1 && y == 4 && z == 1) return 2;
    if (x == 3 && y == 3 && z == 2) return 4;
    if (x == 3 && y == 2 && z == 3) return 4;
    if (x == 4 && y == 3 && z == 2) return 2;
    if (x == 4 && y == 2 && z == 3) return 2;
    if (x == 2 && y == 1 && z == 4) return 4;
    if (x == 2 && y == 4 && z == 1) return 4;
  } else if (cnt == 3) {
    if (x == 1 && y == 1 && z == 4) return 2;
    if (x == 1 && y == 4 && z == 1) return 2;
    if (x == 3 && y == 3 && z == 2) return 4;
    if (x == 3 && y == 2 && z == 3) return 4;
    if (x == 4 && y == 3 && z == 2) return 2;
    if (x == 4 && y == 2 && z == 3) return 2;
    if (x == 2 && y == 1 && z == 4) return 4;
    if (x == 2 && y == 4 && z == 1) return 4;
  }
  return 0;
}
char str[100];
Gate read() {
  scanf("%s", str + 1);
  Gate now;
  if (str[1] == 'a')
    now.kind = 1;
  else if (str[1] == 'o')
    now.kind = 2;
  else if (str[2] == 'a')
    now.kind = 3;
  else
    now.kind = 4;
  scanf("%s", str + 1);
  int len = strlen(str + 1);
  for (int i = 1; i <= len; i++)
    if (str[i] == 'x') {
      now.x = i;
      break;
    }
  for (int i = now.x + 1; i <= len; i++)
    if (str[i] == 'x') {
      now.y = i;
      break;
    }
  return now;
}
int cnt[5];
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= m; i++) a[i] = read();
  for (int i = 1; i <= k; i++) {
    Gate x = read();
    int t = calc(x, n);
    cnt[t]++;
  }
  int ans = 0;
  if (cnt[1]) ans = max(ans, cnt[1] + cnt[2]);
  if (cnt[3]) ans = max(ans, cnt[3] + cnt[4]);
  printf("%d\n", (ans) ? k - ans : -1);
  return 0;
}
