#include <bits/stdc++.h>
using namespace std;
int cnt[1000][1000], vst[1000][1000], flag;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
  int N, z, T, x, y, i, xx, yy;
  while (scanf("%d%d", &N, &T) == 2) {
    memset(cnt, 0, sizeof(cnt));
    cnt[500][500] = N;
    queue<int> q = queue<int>();
    if (N >= 4) {
      q.push(500);
      q.push(500);
    }
    flag++;
    while (!q.empty()) {
      x = q.front();
      q.pop();
      y = q.front();
      q.pop();
      vst[x][y] = 0;
      z = cnt[x][y] / 4;
      cnt[x][y] %= 4;
      for (i = 0; i < 4; i++) {
        xx = x + dx[i];
        yy = y + dy[i];
        cnt[xx][yy] += z;
        if (cnt[xx][yy] >= 4) {
          if (vst[xx][yy] != flag) {
            vst[xx][yy] = flag;
            q.push(xx);
            q.push(yy);
          }
        }
      }
    }
    for (; T--;) {
      scanf("%d%d", &x, &y);
      if ((x + 500 < 0 || x + 500 >= 1000 || y + 500 < 0 || y + 500 >= 1000))
        puts("0");
      else
        printf("%d\n", cnt[x + 500][y + 500]);
    }
  }
  return 0;
}
