#include <bits/stdc++.h>
int mp[5555][5555], n, t;
int xx[4] = {0, 0, -1, 1}, yy[4] = {1, -1, 0, 0};
void dfs(int x, int y, int numb) {
  mp[x][y] += numb;
  int now = mp[x][y];
  if (mp[x][y] < 4) return;
  mp[x][y] %= 4;
  for (int i = 0; i < 4; i++) {
    dfs(x + xx[i], y + yy[i], now / 4);
  }
}
int main() {
  while (scanf("%d%d", &n, &t) != EOF) {
    memset(mp, 0, sizeof(mp));
    dfs(2000, 2000, n);
    while (t--) {
      int x, y;
      scanf("%d%d", &x, &y);
      if (x + 2000 > 5000 || y + 2000 > 5000 || x + 2000 < 0 || y + 2000 < 0)
        printf("0\n");
      else
        printf("%d\n", mp[x + 2000][y + 2000]);
    }
  }
  return 0;
}
