#include <bits/stdc++.h>
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
using namespace std;
int n, t;
int m[1000][1000];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, 1, -1};
int main() {
  cin >> n >> t;
  m[500][500] = n;
  bool flag = n >= 4;
  int sz = 0;
  while (flag) {
    flag = false;
    for (int i = 500 - sz; i <= 500 + sz; ++i) {
      for (int j = 500 - sz; j <= 500 + sz; ++j) {
        for (int k = 0; k < 4; ++k) m[i + dx[k]][j + dy[k]] += m[i][j] / 4;
        flag |= m[i][j] >= 4;
        if (m[i][j] >= 4) {
          sz = max(sz, max(abs(i - 500), abs(j - 500)) + 1);
        }
        m[i][j] %= 4;
      }
    }
  }
  while (t--) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (max(abs(x), abs(y)) > 500) {
      printf("0\n");
      continue;
    }
    printf("%d\n", m[x + 500][y + 500]);
  }
  return 0;
}
