#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
int m;
int n;
short col[2][2048][2048];
char was[2048][2048];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int cm;
pair<int, int> v[1000000];
int main() {
  int mx = 1024, my = 1024;
  int t;
  cin >> n >> t;
  v[cm++] = make_pair(mx, my);
  col[0][mx][my] = n;
  was[mx][my] = 1;
  int ct = 0;
  while (1) {
    int o = cm;
    int ff = 0;
    for (int i = 0; i < (o); i++) {
      int cx = v[i].first;
      int cy = v[i].second;
      col[1 ^ ct][cx][cy] = 0;
    }
    for (int i = 0; i < (o); i++) {
      int cx = v[i].first;
      int cy = v[i].second;
      int o = col[ct][cx][cy];
      int f = o >= 4;
      if (f) {
        o -= 4;
        ff += f;
        for (int j = 0; j < (4); j++) {
          int nx = cx + dx[j];
          int ny = cy + dy[j];
          if (nx < mx || ny < my) continue;
          if (!was[nx][ny]) {
            v[cm++] = make_pair(nx, ny);
            was[nx][ny] = 1;
          }
          if (nx == mx && cx > mx || ny == my && cy > my)
            col[ct ^ 1][nx][ny] += 2;
          else
            col[ct ^ 1][nx][ny]++;
        }
      }
      col[1 ^ ct][cx][cy] += o;
    }
    ct ^= 1;
    if (!ff) break;
  }
  for (int i = 0; i < (t); i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x = abs(x);
    y = abs(y);
    if (abs(x) >= 1024 || abs(y) >= 1024) {
      cout << 0 << '\n';
    } else
      cout << col[ct][x + 1024][y + 1024] << '\n';
  }
  return 0;
}
