#include <bits/stdc++.h>
using namespace std;
int mod;
long long mat[1 << 9][1 << 9], buf[1 << 9][1 << 9];
int x[100], y[100];
int main() {
  int k, t;
  scanf("%d", &(k));
  mod = 1 << k;
  for (int i = (0); i <= (int)((1 << k) - 1); ++i)
    for (int j = (0); j <= (int)((1 << k) - 1); ++j) {
      scanf("%lld", &mat[i][j]);
    }
  scanf("%d", &(t));
  for (int i = (1); i <= (int)(t); ++i) scanf("%d%d", &(x[i]), &(y[i]));
  int bit = 1;
  for (int q = (0); q <= (int)(k - 1); ++q) {
    map<pair<int, int>, int> M;
    for (int j = (1); j <= (int)(t); ++j) {
      M[make_pair((1LL * bit * x[j] % mod), (1LL * bit * y[j] % mod))] ^= 1;
    }
    bit <<= 1;
    for (pair<pair<int, int>, int> w : M) {
      if ((w).second) {
        int x = (w).first.first, y = (w).first.second;
        for (int i = (0); i <= (int)((1 << k) - 1); ++i)
          for (int j = (0); j <= (int)((1 << k) - 1); ++j) {
            buf[(i + x) % mod][(j + y) % mod] ^= mat[i][j];
          }
      }
    }
    memcpy(mat, buf, sizeof mat);
    memset(buf, 0, sizeof buf);
  }
  int cnt = 0;
  for (int i = (0); i <= (int)((1 << k) - 1); ++i)
    for (int j = (0); j <= (int)((1 << k) - 1); ++j)
      if (mat[i][j]) cnt++;
  printf("%d\n", cnt);
  return 0;
}
