#include <bits/stdc++.h>
using namespace std;
int a[1010][1010], n, x, y, t;
void work(int x, int y) {
  if (a[x][y] < 3) {
    a[x][y]++;
  } else {
    a[x][y] = 0;
    work(x + 1, y);
    work(x - 1, y);
    work(x, y + 1);
    work(x, y - 1);
  }
}
int main() {
  scanf("%d %d", &n, &t);
  for (int i = 1; i <= n; i++) {
    work(500, 500);
  }
  while (t--) {
    scanf("%d %d", &x, &y);
    if (x > 100 || y > 100 || x < -100 || y < -100) {
      printf("0\n");
    } else {
      printf("%d\n", a[x + 500][y + 500]);
    }
  }
  return 0;
}
