#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:200000000")
using namespace std;
int main() {
  char a[400][400] = {0}, b[400][400] = {0};
  int g = 1;
  int t;
  cin >> t;
  if (t > 100)
    a[200][200] = 100;
  else
    a[200][200] = t;
  t -= a[200][200];
  b[200][200] = a[200][200];
  bool ok = true;
  while (ok) {
    ok = false;
    for (int i = 201 - g; (i) < int(200 + g); (i)++)
      for (int j = 201 - g; (j) < int(200 + g); (j)++) {
        if (a[i][j] >= 4) {
          ok = true;
          b[i][j] -= 4;
          b[i][j + 1]++;
          b[i][j - 1]++;
          b[i - 1][j]++;
          b[i + 1][j]++;
        }
      }
    if (b[200][200 + g] > 0) g++;
    if (b[200][200] < 10) {
      int c;
      if (t > 100)
        c = 100;
      else
        c = t;
      b[200][200] += c;
      t -= c;
    }
    for (int i = 201 - g; (i) < int(200 + g); (i)++)
      for (int j = 201 - g; (j) < int(200 + g); (j)++) a[i][j] = b[i][j];
  }
  cin >> t;
  int x, y;
  for (int i = 0; (i) < int(t); (i)++) {
    cin >> x >> y;
    if ((abs(x) >= 200) || (abs(y) >= 200))
      cout << 0 << endl;
    else
      cout << (int)b[200 + y][200 + x] << endl;
  }
  return 0;
}
