#include <bits/stdc++.h>
using namespace std;
int n, t, last;
int f[6005][6005];
inline void dfs(int x, int y, int o) {
  f[x][y] += o;
  int O = f[x][y];
  f[x][y] %= 4;
  if (O < 4) return;
  dfs(x, y + 1, O / 4);
  dfs(x, y - 1, O / 4);
  dfs(x + 1, y, O / 4);
  dfs(x - 1, y, O / 4);
}
int main() {
  scanf("%d%d", &n, &t);
  dfs(2500, 2500, n);
  for (int i = 1; i <= t; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x += 2500, y += 2500;
    if (x > 5000 || y > 5000 || x < 0 || y < 0) {
      printf("0\n");
      continue;
    }
    printf("%d\n", f[x][y]);
  }
  return 0;
}
