#include <bits/stdc++.h>
using namespace std;
int arr[200][200];
void solve(int x, int y) {
  if (arr[x][y] < 3)
    arr[x][y]++;
  else {
    arr[x][y] = 0;
    solve(x + 1, y);
    solve(x - 1, y);
    solve(x, y + 1);
    solve(x, y - 1);
  }
}
int main() {
  int n, t, x, y;
  cin >> n >> t;
  for (int i = 0; i < n; i++) solve(80, 80);
  for (int i = 0; i < t; i++) {
    cin >> x >> y;
    if (x < (-80) || x > 80 || y < (-80) || y > 80)
      cout << 0 << endl;
    else
      cout << arr[x + 80][y + 80] << endl;
  }
  return 0;
}
