#include <bits/stdc++.h>
using namespace std;
const int ZERO = 1000, NMAX = 2010;
const int direct[4][2] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};
int T, table[NMAX][NMAX], UP;
bool in[NMAX][NMAX];
deque<pair<int, int> > Q;
pair<int, int> x;
int main() {
  int i, tmp, p, q;
  scanf("%d %d", &table[ZERO][ZERO], &T);
  Q.push_back(make_pair(ZERO, ZERO));
  in[ZERO][ZERO] = true;
  while (!Q.empty()) {
    x = Q.front();
    Q.pop_front();
    in[x.first][x.second] = false;
    tmp = table[x.first][x.second] / 4;
    UP = max(UP, x.first - ZERO);
    for (i = 0; i < 4; i += 1) {
      table[x.first + direct[i][0]][x.second + direct[i][1]] += tmp;
      if (!in[x.first + direct[i][0]][x.second + direct[i][1]] &&
          table[x.first + direct[i][0]][x.second + direct[i][1]] >= 4) {
        Q.push_back(make_pair(x.first + direct[i][0], x.second + direct[i][1]));
        in[x.first + direct[i][0]][x.second + direct[i][1]] = true;
      }
    }
    table[x.first][x.second] %= 4;
  }
  for (i = 1; i <= T; i += 1) {
    scanf("%d %d", &p, &q);
    if (abs(p) <= UP + 1 && abs(q) <= UP + 1)
      printf("%d\n", table[p + ZERO][q + ZERO]);
    else
      printf("0\n");
  }
  exit(0);
}
