#include <bits/stdc++.h>
using namespace std;
const int N = 300;
int a[2 * N + 1][2 * N + 1] = {0};
int b[2 * N + 1][2 * N + 1] = {0};
int main() {
  int n;
  cin >> n;
  int x0 = N;
  int y0 = N;
  int L = 0;
  a[x0][y0] = n;
  while (true) {
    bool isEnd = true;
    int incL = 0;
    for (int x = x0 - L; x <= x0 + L; ++x) {
      for (int y = y0 - L; y <= y0 + L; ++y) {
        if (a[x][y] >= 4) {
          isEnd = false;
          b[x][y] += -4;
          ++b[x + 1][y];
          ++b[x][y + 1];
          ++b[x - 1][y];
          ++b[x][y - 1];
          if (x == x0 - L || x == x0 + L || y == y0 - L || y == y0 + L) {
            incL = 1;
          }
        }
      }
    }
    L += incL;
    if (isEnd) {
      break;
    }
    for (int x = x0 - L; x <= x0 + L; ++x) {
      for (int y = y0 - L; y <= y0 + L; ++y) {
        a[x][y] += b[x][y];
        b[x][y] = 0;
      }
    }
  }
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    int x;
    int y;
    cin >> x >> y;
    if ((-300 < x && x < 300) && (-300 < y && y < 300)) {
      cout << a[x + x0][y + y0] << endl;
    } else {
      cout << 0 << endl;
    }
  }
  return 0;
}
