#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[200][200], i, j, N, lim, end, t, op[40010][2], size;
  size = 0;
  for (i = 0; i < 200; i++)
    for (j = 0; j < 200; j++) {
      a[i][j] = 0;
    }
  end = 0;
  lim = 100;
  cin >> N;
  a[100][100] = N;
  while (end != 1) {
    end = 1;
    for (i = lim; i <= 200 - lim; i++)
      for (j = lim; j <= 200 - lim; j++)
        if (a[i][j] >= 4) {
          op[size][0] = i;
          op[size][1] = j;
          size++;
          end = 0;
        }
    for (i = 0; i < size; i++) {
      a[op[i][0] + 1][op[i][1]] += a[op[i][0]][op[i][1]] / 4;
      a[op[i][0] - 1][op[i][1]] += a[op[i][0]][op[i][1]] / 4;
      a[op[i][0]][op[i][1] + 1] += a[op[i][0]][op[i][1]] / 4;
      a[op[i][0]][op[i][1] - 1] += a[op[i][0]][op[i][1]] / 4;
      a[op[i][0]][op[i][1]] = a[op[i][0]][op[i][1]] % 4;
      if (op[i][0] - 1 < lim) lim = op[i][0] - 1;
    }
    size = 0;
  }
  int x, y;
  cin >> t;
  for (i = 0; i < t; i++) {
    cin >> x >> y;
    if (x < -99 || y < -99 || x > 99 || y > 99) {
      cout << "0" << endl;
    } else
      cout << a[x + 100][y + 100] << endl;
  }
  return 0;
}
