#include <bits/stdc++.h>
template <class T>
bool read(T &x) {
  char *s;
  s = (char *)malloc(10);
  if (sizeof(x) == 1)
    strcpy(s + 1, " %c");
  else if (sizeof(x) == 4)
    strcpy(s + 1, "%d");
  else if (sizeof(x) == 8)
    strcpy(s + 1, "%lld");
  int k = scanf(s + 1, &x);
  free(s);
  return k != -1;
}
using namespace std;
int a[400][400], b[400][400];
int main() {
  int i, j, t, x, y, ok = 1;
  cin >> a[89][89] >> t;
  while (ok) {
    ok = 0;
    memset(b, 0, sizeof b);
    for (int i = 1; i <= 180; i++)
      for (int j = 1; j <= 180; j++) {
        if (a[i][j] < 4) continue;
        b[i][j] -= a[i][j] / 4 * 4;
        b[i + 1][j] += a[i][j] / 4;
        b[i - 1][j] += a[i][j] / 4;
        b[i][j + 1] += a[i][j] / 4;
        b[i][j - 1] += a[i][j] / 4;
        ok = 1;
      }
    for (int i = 0; i <= 180; i++)
      for (int j = 0; j <= 180; j++) a[i][j] += b[i][j];
  }
  while (t--) {
    cin >> x >> y;
    if (abs(x) > 87 or abs(y) > 87)
      cout << 0 << endl;
    else
      cout << a[x + 89][y + 89] << endl;
  }
}
