#include <bits/stdc++.h>
const int MAXN = 131;
const int ox = 65;
const int oy = 65;
int a[MAXN][MAXN], b[MAXN][MAXN];
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
void init() {
  int i, j, k;
  memset(b, 0, sizeof(b));
  int p = MAXN - 1;
  bool ok = false;
  for (i = 1; i <= p; i++)
    for (j = 1; j <= p; j++)
      if (a[i][j] > 3) {
        for (k = 0; k < 4; k++) b[i + dx[k]][j + dy[k]] += a[i][j] / 4;
        b[i][j] -= a[i][j] / 4 * 4;
      }
  for (i = 1; i <= p; i++)
    for (j = 1; j <= p; j++) {
      a[i][j] += b[i][j];
      if (a[i][j] > 3) ok = true;
    }
  if (ok) init();
}
int main() {
  int n, x, y, T;
  scanf("%d%d", &n, &T);
  a[ox][oy] = n;
  init();
  while (T--) {
    scanf("%d%d", &x, &y);
    x += ox;
    y += oy;
    if (x >= MAXN || y >= MAXN || x < 0 || y < 0)
      puts("0");
    else
      printf("%d\n", a[x][y]);
  }
  return 0;
}
