#include <bits/stdc++.h>
using namespace std;
int f[100 * 2][100 * 2];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
void distr(int x, int y) {
  int b = f[y][x] / 4;
  for (int i = 0; i < 4; ++i) {
    int mx = x + dx[i];
    int my = y + dy[i];
    f[my][mx] += b;
  }
  f[y][x] %= 4;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  f[100][100] = n;
  while (true) {
    bool flg = false;
    for (int i = 0; i < 100 * 2; ++i) {
      for (int j = 0; j < 100 * 2; ++j) {
        if (f[i][j] >= 4) {
          distr(j, i);
          flg = true;
        }
      }
    }
    if (!flg) break;
  }
  for (int i = 0; i < m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    x += 100;
    y += 100;
    bool flg = false;
    if (x < 0 || y < 0) flg = true;
    if (x >= 2 * 100 || y >= 2 * 100) flg = true;
    if (flg)
      printf("0\n");
    else
      printf("%d\n", f[y][x]);
  }
  return 0;
}
