#include <bits/stdc++.h>
using namespace std;
int ll = 130;
int n, t;
int a[500][500], b[500][500];
int main() {
  cin >> n >> t;
  memset(a, 0, sizeof(a));
  a[ll][ll] = n;
  while (true) {
    int ff = 0, l = ll;
    for (register int i = 1; i <= l * 2; i++)
      for (register int j = 1; j <= l * 2; j++)
        if (a[i][j] >= 4) {
          int t = a[i][j] >> 2;
          ff = 1;
          a[i + 1][j] += t;
          a[i][j + 1] += t;
          a[i - 1][j] += t;
          a[i][j - 1] += t;
          a[i][j] = a[i][j] & 3;
        }
    if (!ff) break;
  }
  for (int i = 0; i < t; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (abs(x) <= ll && abs(y) <= ll)
      printf("%d\n", a[x + ll][y + ll]);
    else
      printf("0\n");
  }
}
