#include <bits/stdc++.h>
using namespace std;
const int BX = 128, BY = 128;
int table[BX * 2][BY * 2];
pair<int, int> stk[BX * BY];
int main() {
  int N, T;
  scanf("%d%d", &N, &T);
  int len = 0;
  stk[len++] = pair<int, int>(BX, BY);
  table[BX][BY] = N;
  int total = 0;
  while (len--) {
    pair<int, int> p = stk[len];
    int m = table[p.first][p.second] / 4;
    table[p.first][p.second] %= 4;
    for (int d = 0; d < 4; d++) {
      int dx = p.first + "1210"[d] - '1';
      int dy = p.second + "2101"[d] - '1';
      if (table[dx][dy] < 4 && table[dx][dy] + m >= 4)
        stk[len++] = pair<int, int>(dx, dy);
      table[dx][dy] += m;
    }
  }
  while (T--) {
    int x, y;
    scanf("%d%d", &x, &y);
    x += BX;
    y += BY;
    if (0 <= x && x < BX * 2 && 0 <= y && y <= BY * 2)
      printf("%d\n", table[x][y]);
    else
      puts("0");
  }
  return 0;
}
