#include <bits/stdc++.h>
using namespace std;
const int mmax = 5000;
typedef struct pnt {
  int x;
  int y;
} pnt;
queue<pnt> q[2];
int grap[mmax][mmax];
int main() {
  int n, t, origin = mmax >> 1;
  int slct = 0;
  pnt tmp, ttmp;
  while (!q[0].empty()) q[0].pop();
  while (!q[1].empty()) q[1].pop();
  cin >> n >> t;
  grap[origin][origin] = n;
  if (n >= 4) {
    tmp.x = origin;
    tmp.y = origin;
    q[slct].push(tmp);
    grap[tmp.x][tmp.y] -= 4;
  }
  while (!q[slct].empty()) {
    while (!q[slct].empty()) {
      tmp = q[slct].front();
      q[slct].pop();
      if (grap[tmp.x][tmp.y] >= 4) {
        grap[tmp.x][tmp.y] -= 4;
        q[slct ^ 1].push(tmp);
      }
      if (++grap[tmp.x - 1][tmp.y] >= 4) {
        grap[tmp.x - 1][tmp.y] -= 4;
        ttmp.x = tmp.x - 1;
        ttmp.y = tmp.y;
        q[slct ^ 1].push(ttmp);
      }
      if (++grap[tmp.x + 1][tmp.y] >= 4) {
        grap[tmp.x + 1][tmp.y] -= 4;
        ttmp.x = tmp.x + 1;
        ttmp.y = tmp.y;
        q[slct ^ 1].push(ttmp);
      }
      if (++grap[tmp.x][tmp.y + 1] >= 4) {
        grap[tmp.x][tmp.y + 1] -= 4;
        ttmp.x = tmp.x;
        ttmp.y = tmp.y + 1;
        q[slct ^ 1].push(ttmp);
      }
      if (++grap[tmp.x][tmp.y - 1] >= 4) {
        grap[tmp.x][tmp.y - 1] -= 4;
        ttmp.x = tmp.x;
        ttmp.y = tmp.y - 1;
        q[slct ^ 1].push(ttmp);
      }
    }
    slct ^= 1;
  }
  int tx, ty;
  for (int i = 0; i < t; i++) {
    cin >> tx >> ty;
    if ((tx + origin >= 0) && (tx + origin < mmax) && (ty + origin >= 0) &&
        (ty + origin < mmax))
      cout << grap[origin + tx][origin + ty] << endl;
    else
      cout << "0" << endl;
  }
  return 0;
}
