#include <bits/stdc++.h>
using namespace std;
const int N = 500 + 3;
const int p = 200;
int a[2][N][N], n, Q, cur = 0, dir[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};
bool vis[N][N];
bool in(int x, int y) { return 0 <= x && x <= 400 && 0 <= y && y <= 400; }
struct note {
  int x, y, v;
  note() {}
  note(int _x, int _y, int _v) {
    x = _x;
    y = _y;
    v = _v;
  }
};
int main() {
  scanf("%d%d", &n, &Q);
  memset(a, 0, sizeof a);
  a[cur][p][p] = n;
  queue<note> q;
  queue<pair<int, int> > qq;
  if (n >= 4) qq.push(make_pair(p, p));
  while (1) {
    bool f = 0;
    while (!qq.empty()) {
      int i = qq.front().first, j = qq.front().second;
      qq.pop();
      f = 1;
      a[cur ^ 1][i][j] = a[cur][i][j] % 4;
      q.push(note(i, j, a[cur][i][j] / 4));
      a[cur][i][j] %= 4;
      vis[i][j] = 0;
    }
    if (!f) break;
    cur ^= 1;
    while (!q.empty()) {
      note u = q.front();
      q.pop();
      int nx, ny;
      for (int i = 0; i < 4; i++) {
        nx = u.x + dir[i][0];
        ny = u.y + dir[i][1];
        if (!in(nx, ny)) continue;
        a[cur][nx][ny] += u.v;
        a[cur ^ 1][nx][ny] = a[cur][nx][ny];
        if (a[cur][nx][ny] >= 4) {
          if (!vis[nx][ny]) {
            vis[nx][ny] = 1;
            qq.push(make_pair(nx, ny));
          }
        }
      }
    }
  }
  for (int i = 0; i < Q; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x += p, y += p;
    if (!in(x, y))
      printf("0\n");
    else
      printf("%d\n", a[cur][x][y]);
  }
  return 0;
}
