#include <bits/stdc++.h>
using namespace std;
long long x, y, n, t;
int a[202][202];
void go(int x, int y) {
  if (a[x][y] < 4) return;
  int g = a[x][y] / 4;
  a[x][y] %= 4;
  a[x][y - 1] += g;
  go(x, y - 1);
  a[x][y + 1] += g;
  go(x, y + 1);
  a[x - 1][y] += g;
  go(x - 1, y);
  a[x + 1][y] += g;
  go(x + 1, y);
}
int main() {
  cin >> a[100][100];
  go(100, 100);
  cin >> t;
  while (t--) {
    cin >> x >> y;
    x = abs(x + 100);
    y = abs(y + 100);
    if (x > 200 || y > 200) {
      cout << 0 << endl;
      continue;
    }
    cout << a[x][y] << endl;
  }
}
