#include <bits/stdc++.h>
using namespace std;
void Get(int &T) {
  char C;
  bool F = 0;
  for (; C = getchar(), C < '0' || C > '9';)
    if (C == '-') F = 1;
  for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0')
    ;
  F && (T = -T);
}
int F[200][200];
int Need[200][200];
int N;
void Init() { Get(N); }
int M;
void Work() {
  F[100][100] = N;
  for (int Again = 1; Again;) {
    Again = 0;
    for (int i = 35; i <= 165; i++)
      for (int j = 35; j <= 165; j++) {
        Need[i][j] = F[i][j] / 4;
        F[i][j] %= 4;
      }
    for (int i = 35; i <= 165; i++)
      for (int j = 35; j <= 165; j++) {
        if (Need[i][j]) Again = 1;
        F[i - 1][j] += Need[i][j];
        F[i + 1][j] += Need[i][j];
        F[i][j - 1] += Need[i][j];
        F[i][j + 1] += Need[i][j];
        Need[i][j] = 0;
      }
  }
  Get(M);
  for (int k = 1, X, Y; k <= M; k++) {
    Get(X);
    Get(Y);
    X += 100;
    Y += 100;
    if (X < 35 || X > 165 || Y < 35 || Y > 165)
      puts("0");
    else
      printf("%d\n", F[X][Y]);
  }
}
int main() {
  Init();
  Work();
  return 0;
}
