#include <bits/stdc++.h>
using namespace std;
int cnt[1111][1111];
bool inq[1111][1111];
int n, t;
queue<pair<int, int> > q;
const int kFx[4] = {-1, 1, 0, 0};
const int kFy[4] = {0, 0, -1, 1};
int main() {
  scanf("%d%d", &n, &t);
  cnt[555][555] = n;
  if (n >= 4) {
    q.push(make_pair(555, 555));
    inq[555][555] = true;
  }
  while (q.size()) {
    pair<int, int> u = q.front();
    q.pop();
    int _x = u.first;
    int _y = u.second;
    inq[_x][_y] = false;
    int z = cnt[_x][_y];
    cnt[_x][_y] = z & 3;
    for (int d = 0; d < 4; ++d) {
      int x = _x + kFx[d];
      int y = _y + kFy[d];
      pair<int, int> v = make_pair(x, y);
      cnt[x][y] += z >> 2;
      if (!inq[x][y] && cnt[x][y] >= 4) q.push(v), inq[x][y] = true;
    }
  }
  for (int x, y; t--;) {
    scanf("%d%d", &x, &y);
    x += 555;
    y += 555;
    if (x < 0 || x >= 1111 || y < 0 || y >= 1111)
      puts("0");
    else
      printf("%d\n", cnt[x][y]);
  }
  return 0;
}
