#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int a[maxn][maxn];
int n, q, x, y;
inline void solve(int x, int y) {
  if (a[x][y] < 3)
    a[x][y]++;
  else {
    a[x][y] = 0;
    solve(x + 1, y);
    solve(x, y + 1);
    solve(x, y - 1);
    solve(x - 1, y);
  }
}
int main() {
  scanf("%d%d", &n, &q);
  for (register int i = 0; i < n; i++) solve(500, 500);
  for (register int i = 0; i < q; i++) {
    scanf("%d%d", &x, &y);
    if (x > 100 || x < -100 || y > 100 || y < -100)
      printf("0\n");
    else
      printf("%d\n", a[x + 500][y + 500]);
  }
  return 0;
}
