#include <bits/stdc++.h>
using namespace std;
const int N = 520;
long long gi() {
  long long x = 0, o = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-') ch = getchar();
  if (ch == '-') o = -1, ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * o;
}
int k, n, t, x[N], y[N];
long long a[N][N], b[N][N];
int main() {
  cin >> k;
  n = 1 << k;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) a[i][j] = gi();
  cin >> t;
  for (int i = 1; i <= t; i++) x[i] = gi() % n, y[i] = gi() % n;
  for (int i = 1; i <= k; i++) {
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++)
        for (int l = 1; l <= t; l++)
          b[j][k] ^= a[(j - x[l] + n) % n][(k - y[l] + n) % n];
    memcpy(a, b, sizeof(b));
    memset(b, 0, sizeof(b));
    for (int j = 1; j <= t; j++) x[j] = x[j] * 2 % n, y[j] = y[j] * 2 % n;
  }
  int ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (a[i][j]) ++ans;
  cout << ans;
  return 0;
}
