#include <bits/stdc++.h>
using namespace std;
const int MAX = 2000;
int matrix[MAX][MAX];
void dfs(int x, int y, int num) {
  matrix[x][y] += num;
  if (matrix[x][y] < 4) return;
  int p = matrix[x][y] / 4;
  matrix[x][y] %= 4;
  dfs(x + 1, y, p);
  dfs(x - 1, y, p);
  dfs(x, y + 1, p);
  dfs(x, y - 1, p);
}
int main() {
  ios::sync_with_stdio(false);
  int n, t;
  int x[50002], y[50002];
  cin >> n >> t;
  for (int i = 1; i <= t; i++) cin >> x[i] >> y[i];
  dfs(MAX / 2, MAX / 2, n);
  for (int i = 1; i <= t; i++) {
    int x1 = x[i] + MAX / 2;
    int y1 = y[i] + MAX / 2;
    if (x1 < MAX && x1 > 0 && y1 < MAX && y1 > 0)
      cout << matrix[x1][y1] << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
