#include <bits/stdc++.h>
using namespace std;
int n, t;
int a[2000 + 5][2000 + 5];
bool c[2000 + 5][2000 + 5];
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
void ini() {
  memset(a, 0, sizeof(a));
  memset(c, 0, sizeof(c));
  a[500][500] = n;
  queue<pair<int, int> > q;
  q.push(make_pair(500, 500));
  while (!q.empty()) {
    pair<int, int> u = q.front();
    q.pop();
    c[u.first][u.second] = 0;
    int k = a[u.first][u.second] / 4;
    for (int i = 0; i < 4; i++) {
      int x = u.first + dx[i];
      int y = u.second + dy[i];
      a[x][y] += k;
      if (!c[x][y] && a[x][y] > 3) {
        q.push(make_pair(x, y));
        c[x][y] = 1;
      }
    }
    a[u.first][u.second] %= 4;
  }
}
int main() {
  cin >> n >> t;
  ini();
  while (t--) {
    long long x, y;
    cin >> x >> y;
    if (abs(x) > 500 || abs(y) > 500)
      cout << 0 << endl;
    else
      cout << a[x + 500][y + 500] << endl;
  }
  return 0;
}
