#include <bits/stdc++.h>
using namespace std;
int v[1005][1005] = {0};
void dfs(int a, int b, int k) {
  v[a][b] += k;
  if (v[a][b] < 4) return;
  v[a][b] -= 4;
  dfs(a, b, 0);
  dfs(a + 1, b, 1);
  dfs(a, b + 1, 1);
  dfs(a - 1, b, 1);
  dfs(a, b - 1, 1);
}
int main() {
  int n, m;
  cin >> n >> m;
  dfs(500, 500, n);
  while (m--) {
    int a, b;
    cin >> a >> b;
    if (a > 500 || a < -500 || b > 500 || b < -500)
      printf("%d\n", 0);
    else
      printf("%d\n", v[a + 500][b + 500]);
  }
  return 0;
}
