#include <bits/stdc++.h>
using namespace std;
int qf, ql;
struct ppair {
  int first, second;
  inline ppair(int x, int y) {
    first = x;
    second = y;
  }
  inline ppair() {}
};
inline ppair make_ppair(int x, int y) { return ppair(x, y); }
ppair q[400000];
int field[4000][4000];
int dx[5] = {0, 0, 1, -1};
int dy[5] = {1, -1, 0, 0};
bool inq[2000 * 2][2000 * 2];
int main() {
  int n;
  scanf("%d", &n);
  memset(field, 0, sizeof field);
  memset(inq, 0, sizeof inq);
  field[0 + 2000][0 + 2000] = n;
  qf = ql = 0;
  q[ql++] = (make_ppair(0, 0));
  int it = 0;
  while (ql != qf) {
    it++;
    ppair p = q[qf++];
    inq[p.first + 2000][p.second + 2000] = false;
    if (qf == 400000) qf = 0;
    if (field[p.first + 2000][p.second + 2000] < 4) continue;
    field[p.first + 2000][p.second + 2000] -= 4;
    if (field[p.first + 2000][p.second + 2000] >= 4) {
      q[ql++] = p;
      inq[p.first + 2000][p.second + 2000] = true;
    }
    if (ql == 400000) ql = 0;
    for (int i = 0; i < 4; i++) {
      field[p.first + 2000 + dx[i]][p.second + 2000 + dy[i]]++;
      if (field[p.first + 2000 + dx[i]][p.second + 2000 + dy[i]] >= 4 &&
          !inq[p.first + 2000 + dx[i]][p.second + 2000 + dy[i]]) {
        q[ql++] = (make_ppair(p.first + dx[i], p.second + dy[i]));
        inq[p.first + 2000 + dx[i]][p.second + 2000 + dy[i]] = true;
      }
      if (ql == 400000) ql = 0;
    }
  }
  int t;
  scanf("%d", &t);
  for (int i = 0; i < t; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (abs(x) <= 2000 && abs(y) <= 2000)
      printf("%d\n", field[2000 + x][2000 + y]);
    else
      printf("0\n");
  }
}
