#include <bits/stdc++.h>
using namespace std;
short a[10005][10005] = {{0}};
int n, t, x, y;
const int fx[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
inline int ok(int x, int y) {
  if (x < 0 || y < 0 || x >= 10005 || y >= 10005) return 0;
  return 1;
}
void Do(int x, int y) {
  int tmp = a[x][y] / 4;
  a[x][y] %= 4;
  for (int i = 0; i < 4; ++i) {
    int xx = x + fx[i][0], yy = y + fx[i][1];
    if (!ok(xx, yy)) continue;
    a[xx][yy] += tmp;
    if (i == 2 && yy == 0) a[xx][yy] += tmp;
    if (i == 3 && xx == 0) a[xx][yy] += tmp;
    if (a[xx][yy] >= 4) Do(xx, yy);
  }
}
inline void init() {
  if (n < 4) return;
  Do(0, 0);
}
int main(int argc, char **argv) {
  scanf("%d%d", &n, &t);
  a[0][0] = n;
  init();
  while (t--) {
    scanf("%d%d", &x, &y);
    if (x < 0) x = -x;
    if (y < 0) y = -y;
    if (x >= 10005 || y >= 10005)
      puts("0");
    else
      printf("%d\n", a[x][y]);
  }
  return 0;
}
