#include <bits/stdc++.h>
using namespace std;
int main() {
  static int a[150][150];
  static int b[150][150];
  memset(a, 0, sizeof(a));
  int x1, x2, y1, y2;
  int st = 150 / 2;
  x1 = 150 / 2;
  x2 = 150 / 2;
  y1 = 150 / 2;
  y2 = 150 / 2;
  int num, Q;
  scanf("%d %d", &num, &Q);
  a[x1][y1] = num;
  int i, j;
  memset(b, 0, sizeof(b));
  while (1) {
    char flag = 0;
    for (i = x1; i <= x2; i++) {
      for (j = x1; j <= x2; j++) {
        if (a[i][j] >= 4) {
          flag = 1;
          b[i][j] -= 4;
          b[i - 1][j]++;
          b[i + 1][j]++;
          b[i][j - 1]++;
          b[i][j + 1]++;
        }
      }
    }
    int x3, x4, y3, y4;
    x3 = x1;
    x4 = x2;
    y3 = y1;
    y4 = y2;
    for (i = x1 - 1; i <= x2 + 1; i++) {
      if (b[i][y1 - 1]) y3 = y1 - 1;
      if (b[i][y2 + 1]) y4 = y2 + 1;
    }
    for (j = y1 - 1; j <= y2 + 1; j++) {
      if (b[x1 - 1][j]) x3 = x1 - 1;
      if (b[x2 + 1][j]) x4 = x2 + 1;
    }
    x1 = x3;
    x2 = x4;
    y1 = y3;
    y2 = y4;
    if (!flag) break;
    for (i = x1; i <= x2; i++) {
      for (j = x1; j <= x2; j++) {
        a[i][j] += b[i][j];
        b[i][j] = 0;
      }
    }
  }
  int iQ;
  for (iQ = 0; iQ < Q; iQ++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x += st;
    y += st;
    if ((x < x1) || (x > x2) || (y < y1) || (y > y2))
      printf("0\n");
    else
      printf("%d\n", a[x][y]);
  }
  return 0;
}
