#include <bits/stdc++.h>
using namespace std;
const int dxy[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
const int maxn = 350 + 10;
const int tmp = 150;
struct node {
  int x, y;
};
bool vis[maxn][maxn];
int w[maxn][maxn];
queue<node> q;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  memset(vis, false, sizeof(vis));
  memset(w, 0, sizeof(w));
  node e = (node){150, 150};
  w[e.x][e.y] = n;
  if (n >= 4) {
    vis[e.x][e.y] = true;
    q.push(e);
  }
  while (!q.empty()) {
    node t = q.front();
    q.pop();
    int d = w[t.x][t.y] / 4;
    w[t.x][t.y] %= 4;
    for (int i = 0; i < 4; i++) {
      int x = t.x + dxy[i][0];
      int y = t.y + dxy[i][1];
      w[x][y] += d;
      if (w[x][y] >= 4 && !vis[x][y]) {
        vis[x][y] = true;
        q.push((node){x, y});
      }
    }
    vis[t.x][t.y] = false;
  }
  while (m--) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x + tmp < 0 || x + tmp >= maxn || y + tmp < 0 || y + tmp >= maxn)
      printf("0\n");
    else
      printf("%d\n", w[x + tmp][y + tmp]);
  }
  return 0;
}
