#include <bits/stdc++.h>
using namespace std;
int v[200 + 10][200 + 10];
bool f[200 + 10][200 + 10];
queue<pair<int, int> > q;
pair<int, int> tmp[10000];
int sz;
int main() {
  int n, t;
  cin >> n >> t;
  int bs = 100;
  for (int i = 0; i <= 200; ++i)
    for (int j = 0; j <= 200; ++j) f[i][j] = false, v[i][j] = 0;
  v[bs][bs] = n;
  if (n >= 4) {
    f[bs][bs] = true;
    q.push(make_pair(bs, bs));
  }
  while (true) {
    if (q.empty()) break;
    int i, j;
    sz = 0;
    while (!q.empty()) {
      i = q.front().first;
      j = q.front().second;
      q.pop();
      f[i][j] = false;
      v[i][j] -= 4;
      ++v[i + 1][j];
      ++v[i - 1][j];
      ++v[i][j - 1];
      ++v[i][j + 1];
      tmp[sz++] = make_pair(i, j);
    }
    for (int t = 0; t < sz; ++t) {
      i = tmp[t].first;
      j = tmp[t].second;
      if (v[i][j] >= 4 && !f[i][j]) {
        f[i][j] = true;
        q.push(make_pair(i, j));
      }
      if (v[i + 1][j] >= 4 && !f[i + 1][j]) {
        f[i + 1][j] = true;
        q.push(make_pair(i + 1, j));
      }
      if (v[i - 1][j] >= 4 && !f[i - 1][j]) {
        f[i - 1][j] = true;
        q.push(make_pair(i - 1, j));
      }
      if (v[i][j - 1] >= 4 && !f[i][j - 1]) {
        f[i][j - 1] = true;
        q.push(make_pair(i, j - 1));
      }
      if (v[i][j + 1] >= 4 && !f[i][j + 1]) {
        f[i][j + 1] = true;
        q.push(make_pair(i, j + 1));
      }
    }
  }
  for (int i = 0; i < t; i += 1) {
    int x, y;
    scanf("%d %d", &x, &y);
    if (abs(x) > 65 || abs(y) > 65) {
      printf("0");
    } else {
      printf("%d", v[bs - y][bs + x]);
    }
    printf("\n");
  }
  return 0;
}
