#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int a[1000][1000];
void solve(int x, int y, int n) {
  a[x][y] += n;
  n = a[x][y];
  if (a[x][y] < 4)
    return;
  else {
    a[x][y] = n % 4;
    solve(x + 1, y, n / 4);
    solve(x, y + 1, n / 4);
    solve(x, y - 1, n / 4);
    solve(x - 1, y, n / 4);
  }
}
int main() {
  int n = read(), q = read();
  solve(500, 500, n);
  for (int i = 0; i < q; i++) {
    int x = read(), y = read();
    if (x > 100 || x < -100 || y > 100 || y < -100)
      cout << "0" << endl;
    else
      printf("%d\n", a[x + 500][y + 500]);
  }
}
