#include <bits/stdc++.h>
using namespace std;
queue<pair<int, int> > q;
int c[2048][2048];
int dr[4] = {-1, 0, 1, 0};
int dc[4] = {0, 1, 0, -1}, nr, nc;
int main() {
  int n, t, x, y;
  scanf("%d%d", &n, &t);
  c[1023][1023] = n;
  q.push(make_pair(1023, 1023));
  pair<int, int> s;
  int mxr = 1023, mxc = 1023;
  while (!q.empty()) {
    s = q.front();
    q.pop();
    if (c[s.first][s.second] < 4) continue;
    for (int k = 0; k < 4; ++k) {
      nr = s.first + dr[k];
      nc = s.second + dc[k];
      c[nr][nc] += c[s.first][s.second] / 4;
      if (c[nr][nc] >= 4) q.push(make_pair(nr, nc));
    }
    c[s.first][s.second] %= 4;
  }
  ++t;
  while (--t) {
    scanf("%d%d", &x, &y);
    x += 1023;
    y += 1023;
    if (x < 0 || x > 2047 || y < 0 || y > 2047)
      printf("0\n");
    else
      printf("%d\n", c[y][x]);
  }
  return 0;
}
