#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000, mi = 500;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int n, m, v[maxn][maxn];
void dfs(const int x, const int y) {
  int w = v[x][y] >> 2;
  v[x][y] &= 3;
  if (w == 0) return;
  for (int i = 0; i < 4; ++i) {
    int a = x + dx[i];
    int b = y + dy[i];
    v[a][b] += w;
    if (v[a][b] >= 4) dfs(a, b);
  }
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    v[mi][mi] = n;
    dfs(mi, mi);
    int x, y;
    for (int i = 0; i < m; ++i) {
      scanf("%d%d", &x, &y);
      x += mi;
      y += mi;
      if (x >= 0 && x < maxn && y >= 0 && y < maxn)
        printf("%d\n", v[x][y]);
      else
        printf("0\n");
    }
  }
  return 0;
}
