#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, M[129][129];
  memset(M, 0, sizeof M);
  scanf("%d", &n);
  M[64][64] = n;
  vector<pair<int, int> > s1, s2;
  bool used[129][129];
  if (n >= 4) s1.push_back(make_pair(64, 64));
  int it = 0;
  while (!s1.empty()) {
    memset(used, false, sizeof used);
    s2.clear();
    for (int i = s1.size() - 1; i >= 0; --i) {
      int cx = s1[i].first, cy = s1[i].second;
      M[cx][cy] -= 4;
    }
    for (int i = s1.size() - 1; i >= 0; --i) {
      int cx = s1[i].first, cy = s1[i].second;
      if (cx == 0 || cy == 0 || cx == 128 || cy == 128) cout << ":O" << endl;
      ++M[cx - 1][cy];
      ++M[cx + 1][cy];
      ++M[cx][cy - 1];
      ++M[cx][cy + 1];
      if (M[cx - 1][cy] >= 4 && !used[cx - 1][cy])
        s2.push_back(make_pair(cx - 1, cy)), used[cx - 1][cy] = true;
      if (M[cx + 1][cy] >= 4 && !used[cx + 1][cy])
        s2.push_back(make_pair(cx + 1, cy)), used[cx + 1][cy] = true;
      if (M[cx][cy - 1] >= 4 && !used[cx][cy - 1])
        s2.push_back(make_pair(cx, cy - 1)), used[cx][cy - 1] = true;
      if (M[cx][cy + 1] >= 4 && !used[cx][cy + 1])
        s2.push_back(make_pair(cx, cy + 1)), used[cx][cy + 1] = true;
      if (M[cx][cy] >= 4 && !used[cx][cy])
        s2.push_back(make_pair(cx, cy)), used[cx][cy] = true;
    }
    s1 = s2;
  }
  int Q, qx, qy;
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d %d", &qx, &qy);
    if (abs(qx) <= 64 && abs(qy) <= 64)
      printf("%d\n", M[qx + 64][qy + 64]);
    else
      printf("0\n");
  }
  return 0;
}
