#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, t;
  scanf("%d%d", &n, &t);
  vector<vector<int>> m(400, vector<int>(400));
  queue<pair<int, int>> q;
  q.push(pair<int, int>(0, 0));
  m[200][200] = n;
  while (q.size()) {
    pair<int, int> pos = q.front();
    q.pop();
    int x = pos.first;
    int y = pos.second;
    int v = m[200 + x][200 + y];
    if (v < 4) continue;
    m[200 + x][200 + y] = v % 4;
    v /= 4;
    int z = (m[200 + x + 1][200 + y] += v);
    if (z >= 4 && z - v < 4) q.push(pair<int, int>(x + 1, y));
    z = (m[200 + x][200 + y + 1] += v);
    if (z >= 4 && z - v < 4) q.push(pair<int, int>(x, y + 1));
    z = (m[200 + x - 1][200 + y] += v);
    if (z >= 4 && z - v < 4) q.push(pair<int, int>(x - 1, y));
    z = m[200 + x][200 + y - 1] += v;
    if (z >= 4 && z - v < 4) q.push(pair<int, int>(x, y - 1));
  }
  for (int i = 0; i < t; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x + 200 >= 0 && x + 200 < 400 && y + 200 >= 0 && y + 200 <= 400) {
      printf("%d\n", m[x + 200][y + 200]);
    } else {
      printf("0\n");
    }
  }
}
int main() {
  solve();
  return 0;
}
