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