#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void checkmin(T &a, T b) {
  if (a > b) a = b;
}
const int N = 129;
const int M = 64;
int a[N][N], b[N][N];
void solve() {
  int n, t;
  scanf("%d%d", &n, &t);
  a[M][M] = n;
  int maxi = 0, x, y;
  while (1) {
    int f = 0;
    x = M - maxi;
    y = M + maxi;
    for (int i = x; i <= y; i++)
      for (int j = x; j <= y; j++) b[i][j] = a[i][j];
    for (int i = x; i <= y; i++)
      for (int j = x; j <= y; j++) {
        if (a[i][j] >= 4) {
          b[i][j] -= 4;
          b[i + 1][j] += 1;
          b[i - 1][j] += 1;
          b[i][j + 1] += 1;
          b[i][j - 1] += 1;
          f = 1;
          maxi = max(maxi, i + 1 - M);
        }
      }
    x = M - maxi;
    y = M + maxi;
    for (int i = x; i <= y; i++)
      for (int j = x; j <= y; j++) a[i][j] = b[i][j];
    if (f == 0) break;
  }
  for (int i = 0; i < (t); i++) {
    scanf("%d %d", &x, &y);
    if (x < 0) x = -x;
    if (y < 0) y = -y;
    if (x > 64 || y > 64)
      printf("0\n");
    else
      printf("%d\n", a[M + x][M + y]);
  }
}
int main() {
  solve();
  return 0;
}
