#include <bits/stdc++.h>
using namespace std;
int cnt[1100110];
int inq[1100110];
queue<int> q;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
void spfa(int k) {
  int st = (500 << 10) | 500;
  cnt[st] = k;
  if (k < 4) return;
  q.push(st);
  inq[st] = 1;
  while (!q.empty()) {
    st = q.front();
    q.pop();
    int x = st & 1023, y = st >> 10, num = (cnt[st] -= 4);
    if (num < 4)
      inq[st] = 0;
    else
      q.push(st);
    for (int i = 0; i < 4; ++i) {
      int nst = (x + dx[i]) | ((y + dy[i]) << 10);
      int nnum = (cnt[nst] += 1);
      if (nnum < 4) continue;
      if (inq[nst]) continue;
      q.push(nst);
      inq[nst] = 1;
    }
  }
}
int main() {
  int n, t;
  cin >> n >> t;
  spfa(n);
  int x, y;
  while (t--) {
    scanf("%d %d", &x, &y);
    x += 500;
    y += 500;
    if (x < 0 || x > 1000 || y < 0 || y > 1000)
      puts("0");
    else
      printf("%d\n", cnt[(y << 10) | x]);
  }
  return 0;
}
