#include <bits/stdc++.h>
using namespace std;
int M[3000][3000];
void FSet() {
  for (int i = 0; i < 3000; i++)
    for (int j = 0; j < 3000; j++) M[i][j] = 0;
}
void dt(pair<int, int> P, int d) {
  int x = P.first;
  int y = P.second;
  M[x + 1500][y + 1500] += d;
}
int get(pair<int, int> P) {
  int x = P.first;
  int y = P.second;
  return M[x + 1500][y + 1500];
}
void go() {
  queue<pair<int, int> > Q;
  Q.push(make_pair(0, 0));
  while (!Q.empty()) {
    pair<int, int> P = Q.front();
    Q.pop();
    int x = P.first;
    int y = P.second;
    int d = get(make_pair(x, y));
    if (d >= 4) {
      d /= 4;
      dt(make_pair(x, y), -d * 4);
      dt(make_pair(x + 1, y), d);
      dt(make_pair(x - 1, y), d);
      dt(make_pair(x, y + 1), d);
      dt(make_pair(x, y - 1), d);
      if (get(make_pair(x + 1, y)) >= 4) Q.push(make_pair(x + 1, y));
      if (get(make_pair(x - 1, y)) >= 4) Q.push(make_pair(x - 1, y));
      if (get(make_pair(x, y + 1)) >= 4) Q.push(make_pair(x, y + 1));
      if (get(make_pair(x, y - 1)) >= 4) Q.push(make_pair(x, y - 1));
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  FSet();
  int n, k;
  cin >> n >> k;
  dt(make_pair(0, 0), n);
  go();
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    if (abs(x) > 1000 || abs(y) > 1000)
      cout << 0 << endl;
    else
      cout << get(make_pair(x, y)) << endl;
  }
  return 0;
}
