#include <bits/stdc++.h>
using namespace std;
int a[200][200], ans, n;
bool flag = true;
int main() {
  ios::sync_with_stdio(false);
  cin >> a[80][80] >> n;
  while (flag) {
    flag = false;
    for (int i = 1; i < 160; i++)
      for (int j = 1; j < 160; j++)
        if (a[i][j] >= 4) {
          flag = true;
          int k = a[i][j] / 4;
          a[i + 1][j] += k, a[i - 1][j] += k;
          a[i][j + 1] += k, a[i][j - 1] += k;
          a[i][j] -= 4 * k;
        }
  }
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    if (-80 < x && x < 80 && -80 < y && y < 80)
      cout << a[x + 80][y + 80] << '\n';
    else
      cout << 0 << '\n';
  }
  return 0;
}
