#include <bits/stdc++.h>
using namespace std;
int a[220][220] = {0};
void solve(int x, int y, int value) {
  a[x][y] += value;
  int add = a[x][y] / 4;
  a[x][y] %= 4;
  if (add) {
    solve(x + 1, y, add);
    solve(x - 1, y, add);
    solve(x, y + 1, add);
    solve(x, y - 1, add);
  }
}
int main(void) {
  int n;
  cin >> n;
  solve(100, 100, n);
  int tc;
  cin >> tc;
  while (tc--) {
    int x, y;
    cin >> x >> y;
    x += 100;
    y += 100;
    if (x < 0 || x > 200 || y < 0 || y > 200)
      cout << 0 << endl;
    else
      cout << a[x][y] << endl;
  }
  return 0;
}
