#include <bits/stdc++.h>
using namespace std;
const int MAXN = 256;
const int mod = 100;
struct point {
  int x, y;
  point(int x_ = 0, int y_ = 0) {
    x = x_;
    y = y_;
  }
};
int mp[MAXN][MAXN];
int dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
void bfs(int n, int x, int y) {
  int i;
  point cur, tmp;
  queue<point> q;
  mp[x + mod][y + mod] = n;
  if (n >= 4) q.push(point(x + mod, y + mod));
  while (!q.empty()) {
    cur = q.front();
    q.pop();
    mp[cur.x][cur.y] -= 4;
    if (mp[cur.x][cur.y] >= 4) q.push(cur);
    for (i = 0; i < 4; ++i) {
      tmp.x = cur.x + dir[i][0];
      tmp.y = cur.y + dir[i][1];
      mp[tmp.x][tmp.y] += 1;
      if (mp[tmp.x][tmp.y] == 4) q.push(tmp);
    }
  }
}
int main() {
  int i, n, q, x, y;
  scanf("%d %d", &n, &q);
  bfs(n, 0, 0);
  for (i = 0; i < q; ++i) {
    scanf("%d %d", &x, &y);
    x += mod, y += mod;
    if (x < 0 || y < 0 || x > 200 || y > 200)
      printf("0\n");
    else
      printf("%d\n", mp[x][y]);
  }
  return 0;
}
