#include <bits/stdc++.h>
using namespace std;
const int MaxN = 50005, MaxSize = 205, offset = 102;
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
int qx[MaxN], qy[MaxN];
int a[MaxSize][MaxSize];
bool good(int x) { return 0 <= x && x < MaxSize; }
int main() {
  int n, t;
  scanf("%d%d", &n, &t);
  for (int i = 1; i <= t; i++) scanf("%d%d", qx + i, qy + i);
  memset(a, 0, sizeof(a));
  a[offset][offset] = n;
  int maxLeft = offset, maxRight = offset;
  int move = 0, cnt = 0;
  while (true) {
    cnt++;
    bool up = false;
    maxRight = offset + offset - maxLeft;
    int nLeft = maxLeft;
    for (int i = maxLeft - 1; i <= maxRight + 1; ++i) {
      int j = maxLeft - 1;
      if (((i + j) % 2) ^ move == 0) j++;
      for (; j <= maxRight + 1; j += 2)
        for (int k = 0; k < 4; k++) {
          int nx = i + dx[k];
          int ny = j + dy[k];
          a[i][j] += a[nx][ny] / 4;
          if (a[i][j] >= 4 && i == maxLeft - 1) {
            nLeft = i;
          }
          up |= a[nx][ny] >= 4;
        }
    }
    for (int i = maxLeft - 1; i <= maxRight + 1; ++i)
      for (int j = maxLeft - 1; j <= maxRight + 1; ++j)
        if (((i + j) % 2) ^ move == 0) a[i][j] %= 4;
    maxLeft = nLeft;
    move ^= 1;
    if (!up) break;
  }
  for (int i = 1; i <= t; ++i)
    if (abs(qx[i]) >= 100 || abs(qy[i]) >= 100)
      printf("0\n");
    else
      printf("%d\n", a[qx[i] + offset][qy[i] + offset]);
  return 0;
}
