#include <bits/stdc++.h>
using namespace std;
int xx[] = {-1, 0, 1, 0};
int yy[] = {0, 1, 0, -1};
int ans[2 * 1005][2 * 1005];
void DFS(int x, int y) {
  int Val = ans[x][y] / 4;
  ans[x][y] = ans[x][y] % 4;
  if (Val == 0) return;
  for (int i = 0; i <= 3; i++) {
    int u = x + xx[i];
    int v = y + yy[i];
    ans[u][v] += Val;
    DFS(u, v);
  }
}
int main() {
  int n, m, u, v;
  cin >> n >> m;
  ans[1005][1005] = n;
  DFS(1005, 1005);
  for (int i = 1; i <= m; i++) {
    cin >> u >> v;
    if (abs(u) >= 1005 || abs(v) >= 1005)
      cout << 0 << endl;
    else
      cout << ans[u + 1005][v + 1005] << endl;
  }
}
