#include <bits/stdc++.h>
using namespace std;
const long N = 50000;
const long dx[4] = {-1, 1, 0, 0};
const long dy[4] = {0, 0, -1, 1};
long i, n, m, c, tmp, xx, yy, X, Y, x[N], y[N], g[N], f[210][210];
bool h[210][210];
queue<long> t;
bool check(long x, long y) {
  if ((x < 0) || (x > 200)) return false;
  if ((y < 0) || (y > 200)) return false;
  return true;
}
int main() {
  scanf("%ld%ld", &n, &m);
  f[100][100] = c = 1;
  t.push(1);
  x[1] = y[1] = 100;
  h[100][100] = true;
  g[1] = n;
  while (!t.empty()) {
    X = x[t.front()];
    Y = y[t.front()];
    h[X][Y] = false;
    t.pop();
    if (g[f[X][Y]] < 4) continue;
    tmp = g[f[X][Y]] / 4;
    g[f[X][Y]] %= 4;
    for (i = 0; i < 4; i++) {
      xx = X + dx[i];
      yy = Y + dy[i];
      if (f[xx][yy] == 0) {
        f[xx][yy] = ++c;
        x[c] = xx;
        y[c] = yy;
      }
      g[f[xx][yy]] += tmp;
      if ((g[f[xx][yy]] >= 4) && (!h[xx][yy])) {
        t.push(f[xx][yy]);
        h[xx][yy] = true;
      }
    }
  }
  for (i = 0; i < m; i++) {
    scanf("%ld%ld", &X, &Y);
    if (check(X + 100, Y + 100))
      printf("%ld\n", g[f[X + 100][Y + 100]]);
    else
      printf("0\n");
  }
  return 0;
}
