#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > q;
int n, t;
int grid[100][100];
int moves[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int main() {
  cin >> n;
  grid[0][0] = n;
  if (n > 3) q.push_back(make_pair(0, 0));
  int minx = 0;
  int nit = 0;
  while (!q.empty()) {
    nit++;
    pair<int, int> cur = q[q.size() - 1];
    assert(grid[cur.first][cur.second] > 3);
    if (cur.first > minx) minx = cur.first;
    grid[cur.first][cur.second] -= 4;
    if (grid[cur.first][cur.second] < 4) q.pop_back();
    for (int i = 0; i < 4; i++) {
      int nx = cur.first + moves[i][0];
      int ny = cur.second + moves[i][1];
      if (nx < 0 || ny < 0) continue;
      int inc = (1 + (!nx && cur.first)) * (1 + (!ny && cur.second));
      bool ch = grid[nx][ny] < 4;
      grid[nx][ny] += inc;
      if (grid[nx][ny] >= 4 && ch) q.push_back(make_pair(nx, ny));
    }
  }
  minx++;
  cin >> t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    if (a < 0) a *= -1;
    if (b < 0) b *= -1;
    if (a > minx || b > minx)
      cout << 0 << "\n";
    else
      cout << grid[a][b] << "\n";
  }
}
