#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const int N = 3e3 + 5, lg = 27, mod = 5e4 + 7;
int da[N][N];
void solve() {
  int n, t;
  cin >> n >> t;
  queue<pair<int, int>> q;
  q.push({1500, 1500});
  da[1500][1500] = n;
  int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
  while (!q.empty()) {
    int u = q.front().first, v = q.front().second;
    q.pop();
    int z = da[u][v] / 4;
    if (da[u][v] < 4) {
      continue;
    }
    da[u][v] %= 4;
    for (int i = 0; i < 4; i++) {
      int x = u + dx[i], y = v + dy[i];
      da[x][y] += z;
      if ((da[x][y]) / 4) {
        q.push({x, y});
      }
    }
  }
  while (t--) {
    int x, y;
    cin >> x >> y;
    x += 1500, y += 1500;
    if (x < 0 || y < 0 || x >= 3000 || y >= 3000) {
      cout << 0 << endl;
    } else {
      cout << da[x][y] << endl;
    }
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int testCases = 1;
  while (testCases--) {
    solve();
  }
}
