#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& o, const vector<T>& v);
int di[] = {-1, 1, 0, 0};
int dj[] = {0, 0, -1, 1};
struct Board {
  int n, ants;
  vector<vector<int> > B, prev;
  Board(int ants_, int n_) {
    n = n_;
    ants = ants_;
    B = vector<vector<int> >(n, vector<int>(n, 0));
    prev = vector<vector<int> >(n, vector<int>(n, 0));
    B[0][0] = ants;
  }
  bool advance() {
    prev.swap(B);
    for (int i = 0; i < (n); i++)
      for (int j = 0; j < (n); j++) B[i][j] = 0;
    for (int i = 0; i < (n); i++) {
      for (int j = 0; j < (n); j++) {
        if (prev[i][j] >= 4) {
          for (int k = 0; k < (4); k++) {
            int i2 = i + di[k];
            int j2 = j + dj[k];
            if (i2 < 0 || j2 < 0) continue;
            B[i2][j2]++;
            if (i != 0 && j != 0 && (i2 == 0 || j2 == 0)) {
              B[i2][j2]++;
            } else if (i2 == 0 && j2 == 0) {
              B[i2][j2]++;
            }
          }
          B[i][j] += prev[i][j] - 4;
        } else {
          B[i][j] += prev[i][j];
        }
      }
    }
    return B != prev;
  }
  void print() {
    for (int j = 0; j < (n); j++) printf("--");
    printf("\n");
    for (int i = 0; i < (n); i++) {
      bool has = false;
      for (int j = 0; j < (n); j++) {
        if (B[i][j]) has = true;
      }
      if (!has) continue;
      for (int j = 0; j < (n); j++) {
        if (B[i][j])
          printf("%d ", B[i][j]);
        else
          printf("  ");
      }
      printf("\n");
    }
    printf("\n");
  }
  int MX() {
    int res = 0;
    for (int i = 0; i < (n); i++) {
      for (int j = 0; j < (n); j++) {
        if (B[i][j] == 0) continue;
        res = max(res, max(i, j));
      }
    }
    return res;
  }
};
int main() {
  int ants;
  scanf("%d", &ants);
  Board board(ants, 65);
  while (true) {
    if (!board.advance()) {
      break;
    }
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int x, y;
    scanf("%d %d", &x, &y);
    x = abs(x);
    y = abs(y);
    int res;
    if (x >= board.n || y >= board.n) {
      res = 0;
    } else {
      res = board.B[x][y];
    }
    printf("%d\n", res);
  }
}
template <typename T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  bool first = true;
  for (__typeof((v).begin()) x = (v).begin(); x != (v).end(); x++) {
    if (!first) {
      o << ", ";
    }
    o << *x;
    first = false;
  }
  o << "]";
  return o;
}
