#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int inf = 50000000;
const int maxn = 610;
const int off = 305;
int dp[maxn][maxn];
bool vis[maxn][maxn];
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
int main() {
  int n, m, i, j, x, y, nx, ny, maxx = 0, g;
  scanf("%d", &n);
  dp[off][off] = n;
  queue<pair<int, int> > q;
  q.push(make_pair(off, off));
  vis[off][off] = 1;
  while (!q.empty()) {
    x = q.front().first;
    y = q.front().second;
    g = dp[x][y] / 4;
    dp[x][y] -= (g * 4);
    vis[x][y] = 0;
    q.pop();
    if (!g) continue;
    for (i = 0; i < 4; i++) {
      nx = x + dx[i];
      ny = y + dy[i];
      dp[nx][ny] += g;
      if (dp[nx][ny] >= 4 && !vis[nx][ny]) {
        vis[nx][ny] = 1;
        q.push(make_pair(nx, ny));
      }
    }
  }
  scanf("%d", &m);
  while (m--) {
    scanf("%d", &x), scanf("%d", &y);
    x += off, y += off;
    if (x >= maxn || y >= maxn || x < 0 || y < 0) {
      printf("0\n");
      continue;
    }
    printf("%d\n", dp[x][y]);
  }
  return 0;
}
