#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, i, j, k, n, a[300][300];
  scanf("%d %d ", &n, &t);
  for (i = 0; i < 300; i++)
    for (j = 0; j < 300; j++) a[i][j] = 0;
  a[150][150] = n;
  queue<int> x;
  queue<int> y;
  x.push(150);
  y.push(150);
  while (!x.empty()) {
    if (a[x.front()][y.front()] >= 4) {
      a[x.front() + 1][y.front()] += (a[x.front()][y.front()] / 4);
      x.push(x.front() + 1);
      y.push(y.front());
      a[x.front()][y.front() + 1] += (a[x.front()][y.front()] / 4);
      x.push(x.front());
      y.push(y.front() + 1);
      a[x.front() - 1][y.front()] += (a[x.front()][y.front()] / 4);
      x.push(x.front() - 1);
      y.push(y.front());
      a[x.front()][y.front() - 1] += (a[x.front()][y.front()] / 4);
      x.push(x.front());
      y.push(y.front() - 1);
      a[x.front()][y.front()] = a[x.front()][y.front()] % 4;
    }
    x.pop();
    y.pop();
  }
  while (t--) {
    scanf("%d %d", &i, &j);
    if (abs(i) > 299 || abs(j) > 299)
      printf("0\n");
    else
      printf("%d\n", a[i + 150][j + 150]);
  }
  return 0;
}
