#include <bits/stdc++.h>
using namespace std;
const int E = 70;
const int N = 2 * E;
int d[N][N];
int add[N][N];
int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};
bool flag = 1;
int main() {
  int n;
  cin >> n;
  d[E][E] = n;
  while (flag) {
    flag = 0;
    for (int i = 1; i < N - 1; i++) {
      for (int j = 1; j < N - 1; j++) {
        for (int k = 0; k < 4; k++) d[i + dx[k]][j + dy[k]] += d[i][j] / 4;
        d[i][j] %= 4;
      }
    }
    for (int i = 0; i < N; i++)
      for (int j = 0; j < N; j++)
        if (d[i][j] >= 4) flag = 1;
  }
  int m;
  cin >> m;
  for (int q = 0; q < m; q++) {
    int x, y;
    cin >> x >> y;
    if (x + E < N && x + E >= 0 && y + E < N && y + E >= 0)
      cout << d[x + E][y + E];
    else
      cout << 0;
    cout << "\n";
  }
  return 0;
}
