#include <bits/stdc++.h>
using namespace std;
const int N = 600;
unsigned long long w[N][N], tmpw[N][N];
struct Point {
  int x, y;
} p[100], tmpp[100];
int K, n;
int cmp(const Point &a, const Point &b) {
  return a.x == b.x ? a.y < b.y : a.x < b.x;
}
int main() {
  scanf("%d", &K);
  const int U = (1 << K) - 1;
  for (int i = 0; i <= U; i++)
    for (int j = 0; j <= U; j++) scanf("%llu", &w[i][j]);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &p[i].x, &p[i].y), p[i].x &= U, p[i].y &= U;
  tmpp[0].x = -1;
  for (int t = 0; t < K; t++) {
    for (int i = 0; i <= U; i++)
      for (int j = 0; j <= U; j++) {
        unsigned long long tw = w[i][j];
        for (int k = 1; k <= n; k++)
          tmpw[(i + p[k].x) & U][(j + p[k].y) & U] ^= tw;
      }
    for (int i = 0; i <= U; i++)
      for (int j = 0; j <= U; j++) w[i][j] = tmpw[i][j], tmpw[i][j] = 0;
    for (int i = 1; i <= n; i++)
      tmpp[i].x = (p[i].x << 1) & U, tmpp[i].y = (p[i].y << 1) & U;
    sort(tmpp + 1, tmpp + n + 1, cmp);
    int tn = 0;
    for (int i = 1; i <= n; i++)
      if (tmpp[i].x == tmpp[i - 1].x && tmpp[i].y == tmpp[i - 1].y)
        --tn, tmpp[i].x = -1;
      else
        p[++tn] = tmpp[i];
    n = tn;
  }
  int ans = 0;
  for (int i = 0; i <= U; i++)
    for (int j = 0; j <= U; j++)
      if (w[i][j]) ++ans;
  cout << ans << endl;
}
