#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:255000000")
bool firstout = 1;
template <class T>
T &minn(T &a, T b) {
  if (b < a) a = b;
  return a;
}
template <class T>
T &maxx(T &a, T b) {
  if (a < b) a = b;
  return a;
}
int &madd(int &a, int b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
  return a;
}
int &msub(int &a, int b) {
  a -= b;
  if (a < 0) a += 1000000007;
  return a;
}
int &mmult(int &a, int b) { return a = (long long)a * b % 1000000007; }
int mdiv(long long a, long long b, long long m) {
  a = (a % m + m) % m;
  b = (b % m + m) % m;
  if (a % b == 0) return a / b;
  return (a + m * mdiv(-a, m, b)) / b;
}
int DX[4] = {-1, 0, 0, 1};
int DY[4] = {0, -1, 1, 0};
int n, m, q;
int A[1012][1012];
bool B[1012][1012];
int lq, rq;
short QX[(1012 * 1012 * 20)];
short QY[(1012 * 1012 * 20)];
bool valid(int i, int j) {
  return 0 <= i && i < 1012 && 0 <= j && j < (1012 * 1012 * 20);
}
int main() {
  int i, j, k;
  char c;
  int a, d;
  int ts;
  for (ts = 1; scanf("%"
                     "d",
                     &(n)) > 0;
       ++ts) {
    for (i = (0); i < (1012); ++i)
      for (j = (0); j < (1012); ++j) A[i][j] = B[i][j] = 0;
    A[1012 / 2][1012 / 2] = n;
    B[1012 / 2][1012 / 2] = 1;
    lq = rq = 0;
    QX[rq] = 1012 / 2;
    QY[rq++] = 1012 / 2;
    for (; lq < rq; ++lq) {
      i = QX[lq];
      j = QY[lq];
      B[i][j] = 0;
      if (A[i][j] < 4) continue;
      for (k = (0); k < (4); ++k) {
        int ii = i + DX[k];
        int jj = j + DY[k];
        A[ii][jj] += A[i][j] / 4;
        if (!B[ii][jj]) {
          B[ii][jj] = 1;
          QX[rq] = ii;
          QY[rq++] = jj;
        }
      }
      A[i][j] %= 4;
    }
    scanf(
        "%"
        "d",
        &(q));
    for (; q--;) {
      scanf(
          "%"
          "d",
          &(i));
      scanf(
          "%"
          "d",
          &(j));
      i += 1012 / 2;
      j += 1012 / 2;
      if (!valid(i, j))
        printf(
            "%"
            "d",
            (0));
      else
        printf(
            "%"
            "d",
            (A[i][j]));
      printf("\n"), firstout = 1;
    }
  }
  return 0;
}
