#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
void PLAY() {
  cout << fixed << setprecision(10);
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int res[1005][1005];
int main() {
  PLAY();
  int n, t;
  cin >> n >> t;
  queue<pair<int, int>> qu;
  qu.push({0, 0});
  res[300][300] = n;
  while ((int)qu.size()) {
    int curx = qu.front().first;
    int cury = qu.front().second;
    qu.pop();
    if (res[curx + 300][cury + 300] < 4) continue;
    for (int k = 0; k < 4; k++) {
      int tox = dx[k] + curx;
      int toy = dy[k] + cury;
      res[tox + 300][toy + 300] += res[curx + 300][cury + 300] / 4;
      if (res[tox + 300][toy + 300] >= 4) qu.push({tox, toy});
    }
    res[curx + 300][cury + 300] %= 4;
  }
  while (t--) {
    int x, y;
    cin >> x >> y;
    if (abs(x) >= 300 || abs(y) >= 300)
      cout << 0 << endl;
    else
      cout << res[x + 300][y + 300] << endl;
  }
  return 0;
}
