#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const int OFF = 150, MAXC = 2 * OFF + 10;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int q[MAXC][MAXC];
bool inqueue[MAXC][MAXC];
int main() {
  int n, t;
  scanf("%d%d", &n, &t);
  q[OFF][OFF] = n;
  queue<pair<int, int> > fila;
  fila.push(pair<int, int>(0, 0));
  inqueue[OFF][OFF] = 1;
  while (!fila.empty()) {
    pair<int, int> cur = fila.front();
    fila.pop();
    int x = cur.first + OFF, y = cur.second + OFF;
    inqueue[x][y] = 0;
    int add = q[x][y] / 4;
    q[x][y] -= 4 * add;
    if (add) {
      for (int a = 0; a < 4; ++a) {
        int xx = x + dx[a], yy = y + dy[a];
        q[xx][yy] += add;
        if (q[xx][yy] >= 4 && !inqueue[xx][yy]) {
          fila.push(pair<int, int>(xx - OFF, yy - OFF));
          inqueue[xx][yy] = 1;
        }
      }
    }
  }
  while (t--) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (abs(x) > OFF || abs(y) > OFF)
      printf("0\n");
    else
      printf("%d\n", q[x + OFF][y + OFF]);
  }
  return 0;
}
