#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y;
} e[110000];
int a[1100][1100], b, c, d, f, g, h, i, j, k, m, n;
int use[1100][1100];
void add(int x, int y, int v) {
  if (x > d) d = x;
  if (!use[x][y]) {
    m++;
    e[m].x = x;
    e[m].y = y;
    use[x][y] = 1;
  }
  a[x][y] += v;
}
void deal() {
  m = 0;
  scanf("%d%d", &n, &h);
  a[500][500] = n;
  m++;
  e[1].x = 500;
  e[1].y = 500;
  use[500][500] = 1;
  f = 1;
  while (f) {
    f = 0;
    for (i = 1; i <= m; i++)
      if (a[e[i].x][e[i].y] >= 4) {
        b = a[e[i].x][e[i].y] / 4;
        add(e[i].x + 1, e[i].y, b);
        add(e[i].x - 1, e[i].y, b);
        add(e[i].x, e[i].y + 1, b);
        add(e[i].x, e[i].y - 1, b);
        a[e[i].x][e[i].y] %= 4;
        f = 1;
      }
  }
  for (i = 1; i <= h; i++) {
    scanf("%d%d", &c, &d);
    if (c + 500 < 0 || c + 500 > 1000 || d + 500 < 0 || d + 500 > 1000)
      printf("%d\n", 0);
    else
      printf("%d\n", a[500 + c][500 + d]);
  }
}
int main() {
  deal();
  return 0;
}
