#include <bits/stdc++.h>
const int MAXU = 1 << 9 | 1, MAXT = 110;
int K, t, x[MAXT], y[MAXT];
long long a[MAXU][MAXU], b[MAXU][MAXU];
int main() {
  scanf("%d", &K);
  int U = (1 << K) - 1;
  for (int i = 0; i <= U; ++i)
    for (int j = 0; j <= U; ++j) scanf("%lld", &a[i][j]);
  scanf("%d", &t);
  for (int i = 1; i <= t; ++i) scanf("%d%d", x + i, y + i);
  for (int i = 0; i < K; ++i) {
    for (int j = 0; j <= U; ++j)
      for (int k = 0; k <= U; ++k) b[j][k] = 0;
    for (int l = 1; l <= t; ++l)
      for (int j = 0; j <= U; ++j)
        for (int k = 0; k <= U; ++k)
          b[(j + x[l]) & U][(k + y[l]) & U] ^= a[j][k];
    for (int j = 0; j <= U; ++j)
      for (int k = 0; k <= U; ++k) a[j][k] = b[j][k];
    for (int j = 1; j <= t; ++j) x[j] = (x[j] << 1) & U, y[j] = (y[j] << 1) & U;
  }
  int ans = 0;
  for (int i = 0; i <= U; ++i)
    for (int j = 0; j <= U; ++j) ans += !!a[i][j];
  printf("%d\n", ans);
  return 0;
}
