#include <bits/stdc++.h>
const int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
struct Ac {
  int x, y;
} q[60 * 60 * 1000 + 5];
int g[60 + 5][60 + 5], Maxl = 0;
bool vst[60 + 5][60 + 5];
void Bfs() {
  scanf("%d", &g[0][0]);
  int head = 0, tail = 0;
  if (g[0][0] >= 4) {
    q[1].x = 0;
    q[1].y = 0;
    tail++;
  }
  while (head < tail) {
    head++;
    int t = g[q[head].x][q[head].y] / 4;
    g[q[head].x][q[head].y] %= 4;
    vst[q[head].x][q[head].y] = false;
    for (int i = 0; i < 4; i++) {
      int x0 = q[head].x + dx[i];
      int y0 = q[head].y + dy[i];
      if (Maxl < x0) Maxl = x0;
      if (Maxl < y0) Maxl = y0;
      if (x0 >= 0 && y0 >= 0) {
        if ((!x0 && dx[i]) || (!y0 && dy[i]))
          g[x0][y0] += t << 1;
        else
          g[x0][y0] += t;
        if (!vst[x0][y0] && g[x0][y0] >= 4) {
          q[++tail].x = x0;
          q[tail].y = y0;
          vst[x0][y0] = true;
        }
      }
    }
  }
  int m;
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int x0, y0;
    scanf("%d %d", &x0, &y0);
    if (x0 < 0) x0 = -x0;
    if (y0 < 0) y0 = -y0;
    if (x0 > Maxl || y0 > Maxl)
      printf("0\n");
    else
      printf("%d\n", g[x0][y0]);
  }
  return;
}
int main() {
  Bfs();
  getchar();
  getchar();
  return 0;
}
