#include <bits/stdc++.h>
int grid[101][101];
int ukxb[101][101];
int x, y, m = 1;
void Translate() {
  if (x < 0) x = -x;
  if (y < 0) y = -y;
}
bool Propagate() {
  int peak = 0;
  for (y = 0; y <= 0 + m; y++)
    for (x = 0; x <= 0 + m; x++) {
      int ukxn = grid[y][x] % 4;
      ukxn += grid[y][x > 0 ? x - 1 : 1] / 4;
      ukxn += grid[y > 0 ? y - 1 : 1][x] / 4;
      ukxn += grid[y][x + 1] / 4;
      ukxn += grid[y + 1][x] / 4;
      ukxb[y][x] = ukxn;
      if (ukxn > peak) peak = ukxn;
      if (ukxn && x - 0 >= m) m = x - 0 + 1;
    }
  for (y = 0; y < 0 + m; y++)
    for (x = 0; x < 0 + m; x++) {
      grid[y][x] = ukxb[y][x];
    }
  return peak >= 4;
}
int main() {
  int q, n;
  scanf("%d %d", &n, &q);
  x = y = 0;
  Translate();
  grid[y][x] = n;
  while (Propagate())
    ;
  for (; q > 0; q--) {
    scanf("%d %d", &x, &y);
    Translate();
    printf("%d\n", y > 175 || x > 175 ? 0 : grid[y][x]);
  }
  if (0) {
    for (y = 0; y < 101; y++) {
      for (x = 0; x < 101; x++) {
        if (0) {
          printf("%d", grid[y][x]);
        }
      }
      if (0) {
        putchar(10);
      }
    }
  }
  return 0;
}
