#include <bits/stdc++.h>
using namespace std;
queue<pair<int, int> > q;
int arr[200][200];
int add[200][200];
int dy[4] = {0, 0, 1, -1};
int dx[4] = {1, -1, 0, 0};
int main() {
  int n, m;
  cin >> n >> m;
  arr[100][100] = n;
  q.push({100, 100});
  bool good = true;
  while (good) {
    good = false;
    memset(add, 0, sizeof(add));
    while (!q.empty()) {
      int y = q.front().first;
      int x = q.front().second;
      q.pop();
      for (int k = 0; k < 4; k++) {
        int nx = x + dx[k];
        int ny = y + dy[k];
        add[ny][nx] += arr[y][x] / 4;
      }
    }
    for (int i = 0; i < 200; i++)
      for (int j = 0; j < 200; j++) {
        arr[i][j] %= 4;
        arr[i][j] += add[i][j];
        if (arr[i][j] >= 4) {
          good = true;
          q.push({i, j});
        }
      }
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x += 100;
    y += 100;
    if (x >= 0 && x < 200 && y >= 0 && y < 200) {
      cout << arr[y][x] << "\n";
    } else {
      cout << 0 << "\n";
    }
  }
  return 0;
}
