#include <bits/stdc++.h>
using namespace std;
int grid[8000][8000];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
bool inRange(int x, int y) { return x >= 0 && y >= 0 && x < 8000 && y < 8000; }
int main() {
  for (int i = 0; i < 8000; i++)
    for (int j = 0; j < 8000; j++) grid[i][j] = 0;
  int N, T;
  cin >> N >> T;
  queue<pair<int, int> > q;
  q.push(make_pair(0, 0));
  grid[0][0] = N;
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    int x = p.first, y = p.second;
    if (grid[x][y] < 4) continue;
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (!inRange(nx, ny)) continue;
      if (nx == 0 && ny == 0) {
        grid[nx][ny] += (grid[x][y] / 4) * 2;
      } else if (nx == 0 || ny == 0) {
        grid[nx][ny] += (grid[x][y] / 4) * ((x == 0 || y == 0) ? 1 : 2);
      } else {
        grid[nx][ny] += (grid[x][y] / 4);
      }
      if (grid[nx][ny] >= 4) q.push(make_pair(nx, ny));
    }
    grid[x][y] = grid[x][y] % 4;
  }
  for (int i = 0; i < T; i++) {
    int x, y;
    cin >> x >> y;
    x = abs(x);
    y = abs(y);
    if (inRange(x, y))
      cout << grid[x][y] << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
