#include <bits/stdc++.h>
using namespace std;
int f[2 * 100 + 10][2 * 100 + 10];
vector<pair<int, int> > v;
void insert(int x, int y, int d) {
  if ((f[x][y] < 4) && (f[x][y] + d >= 4)) v.push_back(make_pair(x, y));
  f[x][y] += d;
}
int get(int x, int y) {
  if (x < -100) return 0;
  if (x >= 100) return 0;
  if (y < -100) return 0;
  if (y >= 100) return 0;
  return f[x + 100][y + 100];
}
int d[4][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
int main() {
  int n, m;
  while (scanf("%d %d ", &n, &m) != EOF) {
    for (int i = 0; i < 2 * 100 + 10; ++i)
      for (int j = 0; j < 2 * 100 + 10; ++j) f[i][j] = 0;
    v.clear();
    insert(100, 100, n);
    for (int i = 0; i < v.size(); ++i) {
      int x = v[i].first;
      int y = v[i].second;
      int s = f[x][y] / 4;
      f[x][y] -= s * 4;
      for (int j = 0; j < 4; ++j) insert(x + d[j][0], y + d[j][1], s);
    }
    for (int i = 0; i < m; ++i) {
      int x, y;
      scanf("%d %d ", &x, &y);
      cout << get(x, y) << endl;
    }
  }
}
