#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 3000 + 10, mod = 1000000007;
int a[MAX_N][MAX_N], n, t;
void make(int x, int y) {
  a[x - 1][y] += a[x][y] / 4;
  a[x][y - 1] += a[x][y] / 4;
  a[x + 1][y] += a[x][y] / 4;
  a[x][y + 1] += a[x][y] / 4;
  a[x][y] %= 4;
  if (a[x - 1][y] >= 4) make(x - 1, y);
  if (a[x][y - 1] >= 4) make(x, y - 1);
  if (a[x + 1][y] >= 4) make(x + 1, y);
  if (a[x][y + 1] >= 4) make(x, y + 1);
}
int32_t main() {
  cin >> n >> t;
  a[1500][1500] = n;
  make(1500, 1500);
  int x, y;
  while (t--) {
    cin >> x >> y;
    x += 1500, y += 1500;
    if (x >= 3000 || y >= 3000 || x < 0 || y < 0)
      cout << "0" << '\n';
    else
      cout << a[x][y] << '\n';
  }
  return 0;
}
