#include <bits/stdc++.h>
using namespace std;
const int d = 200;
const int X[4] = {-1, 1, 0, 0};
const int Y[4] = {0, 0, 1, -1};
int n, t, x, y, tx, ty, dk;
int a[2 * d + 10][2 * d + 10];
bool use[2 * d + 10][2 * d + 10];
queue<pair<int, int> > q;
int main() {
  cin >> n >> t;
  a[d][d] = n;
  q.push(make_pair(d, d));
  use[d][d] = 1;
  while (!q.empty()) {
    tx = q.front().first, ty = q.front().second;
    q.pop();
    use[tx][ty] = 0;
    if (a[tx][ty] < 4) continue;
    dk = a[tx][ty] / 4;
    a[tx][ty] -= 4 * dk;
    for (int i = 0; i < 4; i++) {
      a[tx + X[i]][ty + Y[i]] += dk;
      if (a[tx + X[i]][ty + Y[i]] >= 4 && use[tx + X[i]][ty + Y[i]] == 0) {
        q.push(make_pair(tx + X[i], ty + Y[i]));
        use[tx + X[i]][ty + Y[i]] == 1;
      }
    }
  }
  for (int i = 0; i < t; i++) {
    scanf("%d%d", &x, &y);
    x += d, y += d;
    if (x <= 0 || y <= 0 || x >= 2 * d || y >= 2 * d)
      printf("%d\n", 0);
    else
      printf("%d\n", a[x][y]);
  }
  return 0;
}
