#include <bits/stdc++.h>
using namespace std;
bool dah[135][135];
int m[135][135];
queue<int> q;
int dr[] = {-1, 0, 1, 0};
int dc[] = {0, -1, 0, 1};
int n, nq;
int x, y;
int main() {
  scanf("%d%d", &n, &nq);
  memset(dah, 0, sizeof dah);
  dah[65][65] = 1;
  m[65][65] = n;
  q.push((65 << 10) | 65);
  while (!q.empty()) {
    int ui = q.front() >> 10;
    int uj = q.front() & 1023;
    q.pop();
    int d = m[ui][uj] >> 2;
    m[ui][uj] -= 4 * d;
    for (int i = 0; i < 4; i++) {
      int ni = ui + dr[i];
      int nj = uj + dc[i];
      if (((ni == 65) && (ni != ui)) || ((nj == 65) && (nj != uj))) {
        m[ni][nj] += 2 * d;
      } else {
        m[ni][nj] += d;
      }
      if (m[ni][nj] >= 4 && !dah[ni][nj] && (nj >= 65) && (ni >= 65)) {
        dah[ni][nj] = 1;
        q.push((ni << 10) | nj);
      }
    }
    if (m[ui][uj] >= 4) {
      dah[ui][uj] = 1;
      q.push((ui << 10) | uj);
    } else {
      dah[ui][uj] = 0;
    }
  }
  for (int i = 0; i < nq; i++) {
    scanf("%d%d", &x, &y);
    x = abs(x) + 65;
    y = abs(y) + 65;
    if ((x >= 135) || (y >= 135)) {
      printf("0\n");
    } else {
      printf("%d\n", m[x][y]);
    }
  }
  return 0;
}
