#include <bits/stdc++.h>
using namespace std;
bool vis[203][203];
int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
int a[203][203];
void dfs(int x, int y) {
  if (a[x][y] >= 4) {
    int cnt = a[x][y] / 4;
    a[x][y] -= 4 * cnt;
    for (int k = 0; k < 4; k++) {
      int fx = x + dir[k][0];
      int fy = y + dir[k][1];
      a[fx][fy] += cnt;
      dfs(fx, fy);
    }
  }
}
int n, t;
int main() {
  int i, j;
  scanf("%d%d", &n, &t);
  a[100][100] = n;
  dfs(100, 100);
  for (i = 0; i <= 200; i++)
    for (j = 0; j <= 200; j++)
      if (a[i][j] >= 4) {
        dfs(i, j);
      }
  while (t--) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x < 100 && x > -100 && y < 100 && y > -100)
      printf("%d\n", a[x + 100][y + 100]);
    else
      printf("0\n");
  }
  return 0;
}
