#include <bits/stdc++.h>
using namespace std;
const int MAXN = 6000 + 10;
int n, t, arr[MAXN][MAXN];
void dfs(int i, int j, int val) {
  arr[i][j] += val;
  if (arr[i][j] < 4) return;
  int me = arr[i][j] / 4;
  arr[i][j] %= 4;
  dfs(i + 1, j, me);
  dfs(i - 1, j, me);
  dfs(i, j + 1, me);
  dfs(i, j - 1, me);
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> t;
  dfs(MAXN / 2, MAXN / 2, n);
  for (int i = 0; i < t; i++) {
    int l, r;
    cin >> l >> r;
    l += MAXN / 2;
    r += MAXN / 2;
    if (l < 0 || r < 0 || l > MAXN || r > MAXN) {
      cout << 0 << endl;
      continue;
    }
    cout << arr[l][r] << endl;
  }
  cin >> n;
  return 0;
}
