#include <bits/stdc++.h>
using namespace std;
const int maxt = 5e4 + 100;
pair<long long, long long> a[maxt];
int x[1002][1002];
void f(int a, int b, int c) {
  x[a][b] += c;
  int em = x[a][b] / 4;
  if (em <= 0) {
    return;
  }
  x[a][b] %= 4;
  f(a, b - 1, em);
  f(a, b + 1, em);
  f(a - 1, b, em);
  f(a + 1, b, em);
}
int main() {
  long long n, t;
  cin >> n >> t;
  int asl = 501;
  for (int i = 0; i < t; i++) cin >> a[i].first >> a[i].second;
  f(asl, asl, n);
  for (int i = 0; i < t; i++) {
    a[i].first += asl;
    a[i].second += asl;
    if (a[i].first < 0 || a[i].first >= asl * 2 || a[i].second < 0 ||
        a[i].second >= asl * 2)
      cout << 0 << endl;
    else {
      cout << x[a[i].first][a[i].second] << endl;
    }
  }
  return 0;
}
