#include <bits/stdc++.h>
using namespace std;
int locations[1005][1005];
int s[1000005];
int di[] = {-1, 1, 0, 0};
int dj[] = {0, 0, -1, 1};
inline void add(int x, int y, int v) { locations[500 + x][500 + y] += v; }
inline int get(int x, int y) { return locations[500 + x][500 + y]; }
int main(int argc, char *argv[]) {
  int n, t;
  scanf("%d %d", &n, &t);
  int stop = 0;
  add(0, 0, n);
  if (n >= 4) {
    s[stop++] = 0;
    s[stop++] = 0;
  }
  while (stop) {
    int y = s[--stop], x = s[--stop];
    int value = get(x, y) / 4;
    add(x, y, -value * 4);
    for (int i = 0; i < 4; i++) {
      int v = get(x + di[i], y + dj[i]);
      if (v + value >= 4 && v < 4) {
        s[stop++] = x + di[i];
        s[stop++] = y + dj[i];
      }
      add(x + di[i], y + dj[i], value);
    }
  }
  while (t--) {
    int x, y;
    scanf("%d %d", &x, &y);
    if (fabs(x) > 500 || fabs(y) >= 500)
      puts("0");
    else
      printf("%d\n", get(x, y));
  }
  return 0;
}
