#include <bits/stdc++.h>
using namespace std;
int n, t;
int T[5000][5000];
int used[5000][5000];
queue<pair<int, int> > Q;
void solve() {
  T[2500][2500] = n;
  if (n >= 4) Q.push(pair<int, int>(2500, 2500));
  while (!Q.empty()) {
    pair<int, int> p = Q.front();
    Q.pop();
    int x = p.first, y = p.second;
    int i = T[x][y] / 4;
    T[x][y - 1] += i;
    T[x][y + 1] += i;
    T[x - 1][y] += i;
    T[x + 1][y] += i;
    T[x][y] %= 4;
    if (T[x][y - 1] >= 4 && used[x][y - 1] == 0) {
      used[x][y - 1] = 1;
      Q.push(pair<int, int>(x, y - 1));
    }
    if (T[x][y + 1] >= 4 && used[x][y + 1] == 0) {
      used[x][y + 1] = 1;
      Q.push(pair<int, int>(x, y + 1));
    }
    if (T[x - 1][y] >= 4 && used[x - 1][y] == 0) {
      used[x - 1][y] = 1;
      Q.push(pair<int, int>(x - 1, y));
    }
    if (T[x + 1][y] >= 4 && used[x + 1][y] == 0) {
      used[x + 1][y] = 1;
      Q.push(pair<int, int>(x + 1, y));
    }
    used[x][y] = 0;
  }
}
void write_output(int x, int y) {
  if (x > 1000 || y > 1000 || x < -1000 || y < -1000)
    printf("0\n");
  else
    printf("%d\n", T[x + 2500][y + 2500]);
}
void read_input() {
  scanf("%d%d", &n, &t);
  solve();
  int x, y;
  for (int i = 0; i < t; i++) {
    scanf("%d%d", &x, &y);
    write_output(x, y);
  }
}
int main() {
  read_input();
  return 0;
}
