#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
enum Operator { pand, por, nand, nor };
pair<int, int> link[55][3];
Operator opr[55][3];
int n, m, k;
bool logicEval(Operator opr, bool a, bool b) {
  if (opr == pand) return a && b;
  if (opr == por) return a || b;
  if (opr == nand) return !(a && b);
  if (opr == nor) return !(a || b);
}
int q0[55], q1[55];
int G[55][55];
bool val[55];
int solve(int* edges, int ne, int flag) {
  int ans = 0;
  bool suc = false;
  for (int i = 0; i < ne; i++) {
    int u = link[edges[i]][1].first, v = link[edges[i]][1].second;
    if (link[u][0] == link[v][0]) {
      if (opr[u][0] == pand && opr[v][0] == nand ||
          opr[u][0] == por && opr[v][0] == nor ||
          opr[u][0] == nand && opr[v][0] == pand ||
          opr[u][0] == nor && opr[v][0] == por) {
        suc = true;
        ans++;
        continue;
      }
    }
    set<int> s;
    s.insert(link[u][0].first);
    s.insert(link[u][0].second);
    s.insert(link[v][0].first);
    s.insert(link[v][0].second);
    int sn = s.size();
    if (sn <= 3) {
      int tmp[4];
      int cnt = 0;
      for (std::set<int>::iterator ptr = s.begin(); ptr != s.end(); ptr++)
        tmp[cnt++] = *ptr;
      bool same = true;
      for (int t = 0; t < (1 << sn); t++) {
        for (int j = 0; j < sn; j++) val[tmp[j]] = (t >> j) & 1;
        bool l1 = logicEval(opr[u][0], val[link[u][0].first],
                            val[link[u][0].second]) ^
                  flag;
        bool l2 = logicEval(opr[v][0], val[link[v][0].first],
                            val[link[v][0].second]) ^
                  flag;
        if (logicEval(opr[edges[i]][1], l1, l2) != flag) {
          same = false;
          break;
        }
      }
      if (same) ans++;
    }
  }
  return suc ? ans : 0;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int u = 0; u <= 1; u++) {
    int tot = u == 0 ? m : k;
    for (int i = 0; i < tot; i++) {
      char tmp[8];
      scanf("%s", tmp);
      if (strcmp(tmp, "and") == 0)
        opr[i][u] = pand;
      else if (strcmp(tmp, "or") == 0)
        opr[i][u] = por;
      else if (strcmp(tmp, "nand") == 0)
        opr[i][u] = nand;
      else if (strcmp(tmp, "nor") == 0)
        opr[i][u] = nor;
      char rel[55];
      scanf("%s", rel);
      int maxlen = u ? m : n;
      for (int j = 0; j < maxlen; j++)
        if (rel[j] == 'x') {
          if (link[i][u].first == 0)
            link[i][u].first = j;
          else
            link[i][u].second = j;
        }
    }
  }
  int n0 = 0, n1 = 0;
  for (int i = 0; i < k; i++) {
    if (opr[i][1] == pand || opr[i][1] == nor)
      q0[n0++] = i;
    else
      q1[n1++] = i;
  }
  int ans = max(solve(q0, n0, 0), solve(q1, n1, 1));
  cout << (ans == 0 ? -1 : k - ans) << endl;
  return 0;
}
