#include <bits/stdc++.h>
int a[2000 + 1][2000 + 1];
char pus[2000 + 1][2000 + 1];
int ql[100 * 30000], qc[100 * 30000], st, dr;
int d[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
int main() {
  int n, t, i, x, l, c, nl, nc, cx;
  char g = 1;
  scanf("%d%d", &n, &t);
  st = 0, dr = 1;
  ql[0] = qc[0] = 0;
  pus[0][0] = 1;
  a[0][0] = n;
  while (st != dr) {
    l = ql[st];
    c = qc[st];
    st++;
    if (st == 100 * 30000) st = 0;
    pus[l][c] = 0;
    x = a[l][c] / 4;
    a[l][c] %= 4;
    for (i = 0; i < 4; i++) {
      nl = l + d[i][0];
      nc = c + d[i][1];
      if (nl == 0 && nc == 0)
        cx = 4 * x;
      else if ((l != 0 && nl == 0) || (c != l && nc == nl))
        cx = 2 * x;
      else
        cx = x;
      if (nl >= 0 && nc >= 0 && nl <= nc) {
        a[nl][nc] += cx;
        if (!pus[nl][nc] && a[nl][nc] >= 4) {
          ql[dr] = nl;
          qc[dr] = nc;
          dr++;
          if (dr == 100 * 30000) dr = 0;
          pus[nl][nc] = 1;
        }
      }
    }
  }
  int y, aux;
  for (i = 0; i < t; i++) {
    scanf("%d%d", &x, &y);
    if (x < 0) x = -x;
    if (y < 0) y = -y;
    if (y < x) {
      aux = x;
      x = y;
      y = aux;
    }
    if (x <= 2000 && y <= 2000)
      printf("%d\n", a[x][y]);
    else
      printf("0\n");
  }
  return 0;
}
