#include <bits/stdc++.h>
using namespace std;
int dat[1111][1111];
int ok;
int n, t;
int maxi = 0;
int pos;
int main() {
  cin >> n >> t;
  pos = 500;
  dat[pos][pos] = n;
  ok = 1;
  while (ok) {
    ok = 0;
    for (int i = pos - maxi; i <= pos + maxi; i++) {
      for (int j = pos - maxi; j <= pos + maxi; j++) {
        if (dat[i][j] >= 4) {
          ok = 1;
          int t1 = i - pos, t2 = j - pos;
          if (maxi == max(t1 > 0 ? t1 : -t1, t2 > 0 ? t2 : -t2)) {
            maxi++;
          }
          dat[i - 1][j] += dat[i][j] / 4;
          dat[i + 1][j] += dat[i][j] / 4;
          dat[i][j - 1] += dat[i][j] / 4;
          dat[i][j + 1] += dat[i][j] / 4;
          dat[i][j] %= 4;
        }
      }
    }
  }
  while (t--) {
    int x, y;
    cin >> x >> y;
    if ((x > 0 ? x : -x) > maxi || (y > 0 ? y : -y) > maxi)
      cout << 0 << '\n';
    else
      cout << dat[pos + x][pos + y] << '\n';
  }
}
