#include <bits/stdc++.h>
using namespace std;
int ar[150][150];
int main() {
  int n, t;
  scanf("%d", &n);
  scanf("%d", &t);
  int f = 1;
  int br = 70, bc = 70;
  ar[br][bc] = n;
  int c = 0, iter = 0;
  int maxx, maxy;
  maxx = -1;
  maxy = -1;
  while (f) {
    c = 0;
    iter++;
    for (int(i) = (0); (i) < (141); ++(i)) {
      for (int(j) = (0); (j) < (141); ++(j)) {
        if (ar[i][j] >= 4) {
          c++;
          maxx = max(maxx, i);
          maxy = max(maxy, j);
        }
        int first = ar[i][j] % 4;
        if (i + 1 < 140) {
          ar[i + 1][j] += ar[i][j] / 4;
        }
        if (i - 1 >= 0) {
          ar[i - 1][j] += ar[i][j] / 4;
        }
        if (j + 1 < 140) {
          ar[i][j + 1] += ar[i][j] / 4;
        }
        if (j - 1 >= 0) {
          ar[i][j - 1] += ar[i][j] / 4;
        }
        ar[i][j] = ar[i][j] % 4;
      }
    }
    if (c == 0) break;
  }
  while (t--) {
    int first, second;
    scanf("%d", &first);
    scanf("%d", &second);
    if (first + 70 > 140 || first + 70 < 0 || second + 70 > 140 ||
        second + 70 < 0) {
      printf("0\n");
      continue;
    }
    printf("%d\n", ar[first + 70][second + 70]);
  }
}
