#include <bits/stdc++.h>
using namespace std;
int tab[1000][1000];
void generate_map(int ants) {
  tab[500][500] = ants;
  queue<pair<int, int> > queue;
  if (ants >= 4) queue.push(make_pair(500, 500));
  while (!queue.empty()) {
    pair<int, int> p = queue.front();
    queue.pop();
    int v = tab[p.first][p.second];
    if (v < 4) continue;
    int add = v / 4;
    tab[p.first][p.second] = v % 4;
    tab[p.first + 1][p.second] += add;
    tab[p.first - 1][p.second] += add;
    tab[p.first][p.second + 1] += add;
    tab[p.first][p.second - 1] += add;
    if (tab[p.first - 1][p.second] >= 4)
      queue.push(make_pair(p.first - 1, p.second));
    if (tab[p.first + 1][p.second] >= 4)
      queue.push(make_pair(p.first + 1, p.second));
    if (tab[p.first][p.second + 1] >= 4)
      queue.push(make_pair(p.first, p.second + 1));
    if (tab[p.first][p.second - 1] >= 4)
      queue.push(make_pair(p.first, p.second - 1));
  }
}
int main() {
  int ants, query, x, y;
  scanf("%d %d", &ants, &query);
  generate_map(ants);
  for (int i = 0; i < query; ++i) {
    scanf("%d %d", &x, &y);
    if (x >= 500 || y >= 500 || x <= -500 || y <= -500) {
      cout << 0 << endl;
    } else {
      cout << tab[x + 500][y + 500] << endl;
    }
  }
  return 0;
};
