#include <bits/stdc++.h>
using namespace std;
int a[70][70];
int main() {
  long i, j, n, t, x[50000], y[50000];
  int ri, rj, p;
  bool ch;
  cin >> n >> t;
  for (i = 0; i < t; i++) cin >> x[i] >> y[i];
  if (n <= 3) {
    for (i = 0; i < t; i++)
      if ((x[i] == 0) && (y[i] == 0))
        cout << n << "\n";
      else
        cout << 0 << "\n";
  } else {
    a[0][0] = n % 4;
    a[0][1] = n / 4;
    rj = 2;
    ch = true;
    while (ch) {
      ch = false;
      for (j = 0; j < rj; j++)
        for (i = 0; i <= j; i++)
          if (a[i][j] > 3) {
            rj = (j + 1 == rj) ? rj + 1 : rj;
            p = a[i][j];
            ch = true;
            a[i][j + 1] += p / 4;
            if (i == 1) a[0][j] += 2 * (p / 4);
            if (i > 1) a[i - 1][j] += p / 4;
            if (i == j - 1) {
              a[i + 1][j] += 2 * (p / 4);
              a[i][j - 1] += 2 * (p / 4);
              if (i == 0) a[0][0] += 2 * (p / 4);
            }
            if (i < j - 1) {
              a[i + 1][j] += p / 4;
              a[i][j - 1] += p / 4;
            }
            a[i][j] = p % 4;
          }
    }
    for (i = 0; i < t; i++)
      if ((abs(x[i]) > 69) || (abs(y[i]) > 69))
        cout << 0 << "\n";
      else if (abs(x[i]) > abs(y[i]))
        cout << a[abs(y[i])][abs(x[i])] << "\n";
      else
        cout << a[abs(x[i])][abs(y[i])] << "\n";
  }
}
