#include <bits/stdc++.h>
using namespace std;
int n, m, ans, x[2005], y[2005];
long long a[2005][2005], b[2005][2005];
void mul() {
  memset(b, 0, sizeof(b));
  for (int i = 0; i < (1 << n); i++)
    for (int j = 0; j < (1 << n); j++)
      for (int k = 1; k <= m; k++)
        b[(x[k] + i) % (1 << n)][(y[k] + j) % (1 << n)] ^= a[i][j];
  memcpy(a, b, sizeof(a));
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (1 << n); i++)
    for (int j = 0; j < (1 << n); j++) scanf("%lld", &a[i][j]);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) scanf("%d%d", &x[i], &y[i]);
  for (int i = 0; i < n; i++) {
    mul();
    for (int j = 1; j <= m; j++) {
      x[j] = 2 * x[j] % (1 << n);
      y[j] = 2 * y[j] % (1 << n);
    }
  }
  for (int i = 0; i < (1 << n); i++)
    for (int j = 0; j < (1 << n); j++)
      if (a[i][j]) ans++;
  printf("%d", ans);
}
