#include <bits/stdc++.h>
using namespace std;
int cnt[1005][1005];
int Ox = 505, Oy = 505;
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
queue<pair<int, int> > Q;
bool inq[1005][1005];
inline void init(int n) {
  cnt[Ox][Oy] = n;
  Q.push(make_pair(Ox, Oy));
  pair<int, int> u;
  while (!Q.empty()) {
    u = Q.front();
    Q.pop();
    inq[u.first][u.second] = 0;
    for (int d = 0; d < 4; ++d) {
      int x = u.first + dx[d], y = u.second + dy[d];
      cnt[x][y] += cnt[u.first][u.second] / 4;
      if (cnt[x][y] >= 4) {
        if (!inq[x][y]) {
          inq[x][y] = 1;
          Q.push(make_pair(x, y));
        }
      }
    }
    cnt[u.first][u.second] %= 4;
  }
}
inline bool in(int x, int y) {
  return 0 <= x && x < 1000 && 0 <= y && y < 1000;
}
int main() {
  int n, t;
  scanf("%d%d", &n, &t);
  init(n);
  while (t--) {
    int x, y;
    scanf("%d%d", &x, &y);
    x += Ox;
    y += Oy;
    if (in(x, y))
      printf("%d\n", cnt[x][y]);
    else
      puts("0");
  }
  return 0;
}
