#include <bits/stdc++.h>
using namespace std;
inline int max(int a, int b) { return a > b ? a : b; }
inline int min(int a, int b) { return a < b ? a : b; }
inline int gcd(int a, int b) {
  if (a % b)
    return gcd(b, a % b);
  else
    return b;
}
inline int lcm(int a, int b) { return (a * (b / gcd(a, b))); }
inline int And(int mask, int bit) { return mask & (1 << bit); }
inline int Or(int mask, int bit) { return mask | (1 << bit); }
inline int Xor(int mask, int bit) { return mask & (~(1 << bit)); }
int n, t, x, y, f[2222][2222];
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int main() {
  scanf("%d %d", &n, &t);
  f[1000][1000] = n;
  queue<pair<int, int> > q;
  if (n >= 4) q.push(pair<int, int>(1000, 1000));
  while (!q.empty()) {
    pair<int, int> u = q.front();
    q.pop();
    if (f[u.first][u.second] < 4) continue;
    for (int i = 0; i < 4; i++) {
      int nx = u.first + dx[i];
      int ny = u.second + dy[i];
      f[nx][ny] += (f[u.first][u.second] / 4);
      if (f[nx][ny] >= 4) q.push(pair<int, int>(nx, ny));
    }
    f[u.first][u.second] %= 4;
  }
  for (int i = 0; i < t; i++) {
    scanf("%d %d", &x, &y);
    x += 1000;
    y += 1000;
    if (x < 0 || y < 0 || x >= 2000 || y >= 2000)
      printf("0\n");
    else
      printf("%d\n", f[x][y]);
  }
  return 0;
}
