#include <bits/stdc++.h>
using namespace std;
ifstream Cin("input.txt");
ofstream Cout("output.txt");
const long long INF = (long long)1e15;
int m[401][401] = {};
void Try(int x, int y, int v);
void dfs(int x, int y);
int main() {
  int n, t, i, j, k, x, y, it;
  cin >> n >> k;
  m[200][200] = n;
  dfs(200, 200);
  for (i = 1; i <= k; ++i) {
    cin >> x >> y;
    if (x < -200 || x > 200 || y < -200 || y > 200)
      cout << 0 << endl;
    else
      cout << m[x + 200][y + 200] << endl;
  }
}
void Try(int x, int y, int v) {
  m[x][y] += v;
  if (m[x][y] >= 4) dfs(x, y);
}
void dfs(int x, int y) {
  int d = m[x][y] / 4;
  m[x][y] %= 4;
  Try(x + 1, y, d);
  Try(x - 1, y, d);
  Try(x, y + 1, d);
  Try(x, y - 1, d);
}
