#include <bits/stdc++.h>
using namespace std;
int c[400][400];
const int F = 200;
int que[1000000][2];
int mm[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int main() {
  int i, j, f, n, k, p, q, r, x, y, dx, dy, t;
  scanf("%d", &n);
  for (k = 0; k < n; k++) {
    c[F][F]++;
    if (c[F][F] < 4) continue;
    p = 0;
    q = -1;
    que[0][0] = F;
    que[0][1] = F;
    while (q != p) {
      r = p;
      while (q != r) {
        x = que[++q][0];
        y = que[q][1];
        c[x][y] -= 4;
        for (i = 0; i < 4; i++) {
          dx = x + mm[i][0];
          dy = y + mm[i][1];
          c[dx][dy]++;
          if (c[dx][dy] == 4) {
            que[++p][0] = dx;
            que[p][1] = dy;
          }
        }
      }
    }
  }
  scanf("%d", &t);
  for (k = 0; k < t; k++) {
    scanf("%d %d", &x, &y);
    if (x > 190 || y > 190 || x < -190 || y < -190) {
      puts("0");
    } else {
      printf("%d\n", c[x + F][y + F]);
    }
  }
  return 0;
}
