#include <bits/stdc++.h>
using namespace std;
const int maxN = 32000;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};
int a[1000][1000];
int b[1000][1000];
int x[maxN];
int y[maxN];
int nx[maxN], ny[maxN];
int len, len2;
int used[1000][1000];
int main() {
  int n;
  cin >> n;
  int centerx = 500, centery = 500;
  a[centerx][centery] = n;
  x[0] = centerx, y[0] = centery;
  len = 1;
  int niter = 0;
  queue<pair<int, int> > q;
  q.push(make_pair(centerx, centery));
  ++used[centerx][centery];
  int total = 0;
  while (!q.empty()) {
    pair<int, int> cur = q.front();
    q.pop();
    int cx = cur.first, cy = cur.second;
    --used[cx][cy];
    if (a[cx][cy] >= 4) {
      int val = a[cx][cy] / 4;
      for (int k = 0; k < 4; ++k) {
        a[cx + dx[k]][cy + dy[k]] += val;
        if (!used[cx + dx[k]][cy + dy[k]]) {
          q.push(make_pair(cx + dx[k], cy + dy[k]));
          ++used[cx + dx[k]][cy + dy[k]];
        }
        ++total;
      }
    }
    a[cx][cy] %= 4;
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x < 0) x = -x;
    if (y < 0) y = -y;
    x += centerx, y += centery;
    if (x < 0 || x >= 1000 || y < 0 || y >= 1000) {
      printf("0\n");
    } else {
      printf("%d\n", a[x][y]);
    }
  }
  return 0;
  cout << niter << endl;
  map<pair<int, int>, int> ants;
  ants[make_pair(0, 0)] = n;
  int iter = 0;
  while (true) {
    map<pair<int, int>, int> nants;
    bool good = false;
    for (map<pair<int, int>, int>::iterator it = ants.begin(); it != ants.end();
         ++it) {
      int cx = it->first.first;
      int cy = it->first.second;
      int howmuch = it->second;
      if (howmuch >= 4) {
        for (int k = 0; k < 4; ++k) {
          nants[make_pair(cx + dx[k], cy + dy[k])] += howmuch / 4;
        }
        good = true;
        nants[make_pair(cx, cy)] += howmuch % 4;
      } else {
        nants[make_pair(cx, cy)] += howmuch;
      }
    }
    if (good) {
      ++iter;
      ants = nants;
    } else {
      break;
    }
  }
  cout << iter << endl;
  return 0;
}
