#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long max(long long a, long long b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}
long long min(long long a, long long b) {
  if (a < b) {
    return a;
  } else {
    return b;
  }
}
long long power(long long b, long long e) {
  if (e == 0) return 1;
  if (e % 2)
    return ((b * power((b) * (b), (e - 1) / 2)));
  else
    return power((b) * (b), e / 2);
}
long long modpower(long long b, long long e, long long q) {
  long long MOD = q;
  if (e == 0) return 1;
  if (e % 2)
    return ((b % MOD) * modpower((b % MOD) * (b % MOD), (e - 1) / 2, q)) % MOD;
  else
    return modpower((b % MOD) * (b % MOD), e / 2, q) % MOD;
}
void dpv(vector<long long> v) {
  for (long long i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << '\n';
}
void dpv(vector<pair<long long, long long> > v) {
  for (long long i = 0; i < v.size(); i++) {
    cout << v[i].first << " " << v[i].second << '\n';
  }
}
void dpv(set<long long> v) {
  for (auto i : v) {
    cout << i << " ";
  }
  cout << '\n';
}
const long long A = 500;
const long long N = 1500;
long long t[N][N];
void oblivious() {
  long long n, k;
  cin >> n >> k;
  long long sz = 0;
  t[A][A] = n;
  while (true) {
    bool ok = false;
    for (long long i = A - sz; i <= A + sz; i++) {
      for (long long j = A - sz; j <= A + sz; j++) {
        if (t[i][j] >= 4) {
          if (max(abs(i - A), abs(j - A)) == sz) {
            sz++;
          }
          ok = true;
          t[i - 1][j] += t[i][j] / 4;
          t[i + 1][j] += t[i][j] / 4;
          t[i][j - 1] += t[i][j] / 4;
          t[i][j + 1] += t[i][j] / 4;
          t[i][j] %= 4;
        }
      }
    }
    if (!ok) {
      break;
    }
  }
  for (long long i = 0; i < k; i++) {
    long long x, y;
    cin >> x >> y;
    if (max(abs(x), abs(y)) > sz) {
      cout << 0 << '\n';
    } else {
      cout << t[A + x][A + y] << '\n';
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    oblivious();
  }
  return 0;
}
