#include <bits/stdc++.h>
using namespace std;
long long rdtsc() {
  long long tmp;
  asm("rdtsc" : "=A"(tmp));
  return tmp;
}
const int maxx = 130;
int value[maxx][maxx], tmp[maxx][maxx];
const int shift = maxx / 2;
void push(int y, int x) {
  assert(y && x && y < maxx - 1 && x < maxx - 1);
  int cnt = value[y][x] / 4;
  value[y][x] -= 4 * cnt;
  value[y + 1][x] += cnt;
  value[y - 1][x] += cnt;
  value[y][x + 1] += cnt;
  value[y][x - 1] += cnt;
}
void solver(int n) {
  if (!n) {
    memset(value, 0, sizeof(value));
    return;
  }
  solver(n / 4);
  memcpy(tmp, value, sizeof(value));
  for (int i = 1; i < maxx - 1; i++)
    for (int j = 1; j < maxx - 1; j++) {
      value[i][j] =
          tmp[i - 1][j] + tmp[i][j - 1] + tmp[i][j + 1] + tmp[i + 1][j];
    }
  value[shift][shift] += n % 4;
  while (1) {
    bool ch = 0;
    for (int i = 0; i < maxx; i++)
      for (int j = 0; j < maxx; j++)
        if (value[i][j] >= 4) {
          push(i, j);
          ch = 1;
        }
    if (!ch) break;
  }
}
int main() {
  srand(rdtsc());
  int n, t;
  while (scanf("%d%d", &n, &t) >= 1) {
    solver(n);
    for (int i = -4; i <= 4; i++)
      for (int j = -4; j <= 4; j++)
        fprintf(stderr, "%d%c", value[i + shift][j + shift], " \n"[j == 4]);
    for (int i = 0; i < t; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      x += shift, y += shift;
      if (x < 0 || y < 0 || abs(x) >= maxx || abs(y) >= maxx)
        printf("0\n");
      else
        printf("%d\n", value[y][x]);
    }
  }
  return 0;
}
