#include <bits/stdc++.h>
using namespace std;
long long int modpow(long long int a, long long int n, long long int temp) {
  long long int res = 1;
  while (n > 0) {
    res = (res * res) % temp;
    if (n & 1) res = (res * a) % temp;
    n /= 2;
  }
  return res;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0)
    return (b);
  else
    return (gcd(b % a, a));
}
void f(int a[][1001], int x, int y) {
  if (a[x][y] >= 4) {
    int t = a[x][y] / 4;
    a[x][y + 1] += t;
    a[x + 1][y] += t;
    a[x - 1][y] += t;
    a[x][y - 1] += t;
    a[x][y] = a[x][y] % 4;
    f(a, x + 1, y);
    f(a, x - 1, y);
    f(a, x, y + 1);
    f(a, x, y - 1);
  }
}
int main() {
  int a[1001][1001] = {0};
  int n, q, x, y;
  cin >> n >> q;
  a[500][500] = n;
  f(a, 500, 500);
  while (q--) {
    cin >> x >> y;
    x += 500;
    y += 500;
    if (x > 1000 || y > 1000 || x < 0 || y < 0)
      cout << 0 << endl;
    else
      cout << a[x][y] << endl;
  }
  return 0;
}
