#include <bits/stdc++.h>
using namespace std;
const long long N = 600;
long long n, t, S, ans;
long long x[110], y[110], a[N][N], b[N][N];
signed main() {
  scanf("%lld", &n);
  S = (1 << n);
  for (long long i = 0; i < S; i++)
    for (long long j = 0; j < S; j++) scanf("%lld", &a[i][j]);
  scanf("%lld", &t);
  for (long long i = 1; i <= t; i++)
    scanf("%lld%lld", &x[i], &y[i]), x[i]--, y[i]--;
  for (long long i = 0; i <= n - 1; i++) {
    for (long long p = 0; p < S; p++)
      for (long long q = 0; q < S; q++) b[p][q] = 0;
    for (long long j = 1; j <= t; j++) {
      for (long long p = 0; p < S; p++)
        for (long long q = 0; q < S; q++)
          b[(x[j] + p) % S][(y[j] + q) % S] ^= a[p][q];
    }
    for (long long p = 0; p < S; p++)
      for (long long q = 0; q < S; q++) a[p][q] = b[p][q];
    for (long long j = 1; j <= t; j++) x[j] = x[j] * 2 % S, y[j] = y[j] * 2 % S;
  }
  for (long long i = 0; i < S; i++)
    for (long long j = 0; j < S; j++)
      if (a[i][j]) ans++;
  printf("%lld", ans);
}
