#include <bits/stdc++.h>
using namespace std;
const int maxn = 340;
int cnt[340][340];
int main() {
  int n, t;
  cin >> n >> t;
  cnt[170][170] = n;
  int m = maxn;
  bool fin = false;
  while (!fin) {
    bool flag = false;
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        if (cnt[i][j] >= 4) {
          int x = cnt[i][j] / 4;
          cnt[i - 1][j] += x, cnt[i + 1][j] += x, cnt[i][j - 1] += x,
              cnt[i][j + 1] += x;
          cnt[i][j] %= 4;
          flag = true;
        }
      }
    }
    if (!flag) fin = true;
  }
  for (int i = 0; i < t; i++) {
    int x, y;
    cin >> x >> y;
    if (x + 170 >= 0 && x + 170 < 340 && y + 170 >= 0 && y + 170 < 340)
      cout << cnt[x + 170][y + 170] << endl;
    else
      cout << "0" << endl;
  }
  return 0;
}
