#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
int const N = 5000 + 5, C = N / 2;
int n, t, a[N][N];
inline bool in(int x, int y) {
  x += C, y += C;
  return (0 <= x && x < N && 0 <= y && y < N);
}
void dfs(int x, int y, int val) {
  a[C + x][C + y] += val;
  if (a[C + x][C + y] >= 4) {
    int tmp = a[C + x][C + y] / 4;
    a[C + x][C + y] %= 4;
    dfs(x + 1, y, tmp);
    dfs(x, y + 1, tmp);
    dfs(x - 1, y, tmp);
    dfs(x, y - 1, tmp);
  }
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  dfs(0, 0, n);
  cin >> t;
  while (t--) {
    int x, y;
    cin >> x >> y;
    if (!in(x, y))
      cout << "0\n";
    else
      cout << a[C + x][C + y] << '\n';
  }
}
