#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10, S = N / 2;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int ans = 0;
struct arr {
  int a[N][N];
  int& operator[](pair<int, int> pi) {
    int nima = pi.first;
    int sepanta = pi.second;
    if (nima < 0) nima += S;
    if (sepanta < 0) sepanta += S;
    if (nima >= N || sepanta >= N || nima < 0 || sepanta < 0) return ans;
    return a[nima][sepanta];
  }
} sepi;
int main() {
  int n, t;
  cin >> n >> t;
  sepi[{0, 0}] = n;
  deque<pair<int, int> > dq;
  dq.push_back({0, 0});
  while (!dq.empty()) {
    pair<int, int> pi = dq.front();
    dq.pop_front();
    if (sepi[pi] < 4) continue;
    int add = sepi[pi] / 4;
    sepi[pi] -= add * 4;
    for (int i = 0; i < 4; i++) {
      sepi[{pi.first + dx[i], pi.second + dy[i]}] += add;
      dq.push_back({pi.first + dx[i], pi.second + dy[i]});
    }
  }
  cout << endl;
  while (t--) {
    int x, y;
    cin >> x >> y;
    cout << sepi[{x, y}] << endl;
  }
}
