#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3;
int long long n, t, ans[2000][2000];
queue<pair<int, int>> qu;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> t;
  ans[1000][1000] = n;
  qu.push({0, 0});
  while (qu.size() > 0) {
    auto a = qu.front();
    qu.pop();
    int x = a.first + 1000, y = a.second + 1000;
    if (ans[x][y] < 4) {
      continue;
    }
    for (int i = -1; i <= 1; i++)
      for (int j = -1; j <= 1; j++)
        if (abs(i - j) == 1) {
          ans[x + i][y + j] += ans[x][y] / 4;
          if (ans[x + i][j + y] >= 4) qu.push({x + i - 1000, y + j - 1000});
        }
    ans[x][y] %= 4;
  }
  while (t--) {
    int long long a, b;
    cin >> a >> b;
    if (a + 1e3 < 0 || a + 1e3 > 2e3 || b + 1e3 < 0 || b + 1e3 > 2e3) {
      cout << 0 << endl;
      continue;
    }
    cout << ans[a + 1000][b + 1000] << endl;
  }
}
