#include <bits/stdc++.h>
using namespace std;
int cnt[1000][1000], vst[1000][1000], flag;
int dr[] = {1, 0, -1, 0};
int dc[] = {0, 1, 0, -1};
int main() {
  int N, i, T, v, r, c, rr, cc;
  scanf("%d%d", &N, &T);
  memset(cnt, 0, sizeof(cnt));
  cnt[500][500] = N;
  queue<int> q[2];
  q[0] = q[1] = queue<int>();
  q[0].push(500);
  q[0].push(500);
  v = 1;
  while (1) {
    v = 1 - v;
    flag++;
    if (q[v].empty()) break;
    while (!q[v].empty()) {
      r = q[v].front();
      q[v].pop();
      c = q[v].front();
      q[v].pop();
      if (cnt[r][c] < 4) continue;
      cnt[r][c] -= 4;
      if (cnt[r][c] >= 4) {
        if (vst[r][c] != flag) {
          vst[r][c] = flag;
          q[1 - v].push(r);
          q[1 - v].push(c);
        }
      }
      for (i = 0; i < 4; i++) {
        rr = r + dr[i];
        cc = c + dc[i];
        cnt[rr][cc]++;
        if (cnt[rr][cc] >= 4 && vst[rr][cc] != flag) {
          q[1 - v].push(rr);
          q[1 - v].push(cc);
          vst[rr][cc] = flag;
        }
      }
    }
  }
  for (i = 0; i < T; i++) {
    scanf("%d%d", &r, &c);
    if (abs(r) > 480 || abs(c) > 480)
      puts("0");
    else
      printf("%d\n", cnt[r + 500][c + 500]);
  }
  return 0;
}
