#include <bits/stdc++.h>
using namespace std;
int MAX = 1000000;
int MIN = -1000000;
int INF = 1000000000;
int x4[4] = {0, 1, 0, -1};
int y4[4] = {1, 0, -1, 0};
int x8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int y8[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int i, j, k;
int petak[2000][2000];
bool lebih[2000][2000];
int main() {
  int n, q, x, y;
  queue<pair<int, int> > que;
  memset((lebih), (false), sizeof(lebih));
  ;
  cin >> n >> q;
  petak[0 + 900][0 + 900] = n;
  if (n >= 4) {
    que.push(pair<int, int>(0, 0));
    lebih[0 + 900][0 + 900] = true;
    while (que.size() > 0) {
      x = que.front().first;
      y = que.front().second;
      petak[x + 900][y + 900] -= 4;
      if (petak[x + 900][y + 900] < 4) que.pop();
      for (i = 0; i < 4; i++) petak[x + x4[i] + 900][y + y4[i] + 900]++;
      for (i = 0; i < 4; i++) {
        if (petak[x + x4[i] + 900][y + y4[i] + 900] >= 4)
          if (lebih[x + x4[i] + 900][y + y4[i] + 900] == false) {
            que.push(pair<int, int>((x + x4[i]), (y + y4[i])));
            lebih[x + x4[i] + 900][y + y4[i] + 900] = true;
          }
      }
      if (petak[x + 900][y + 900] < 4) lebih[x + 900][y + 900] = false;
    }
  }
  int a, b;
  for (i = (0); i < (q); i++) {
    scanf("%d %d", &a, &b);
    if (a + 900 < 0 || a + 900 >= 2000 || b + 900 < 0 || b + 900 >= 2000)
      printf("0\n");
    else
      printf("%d\n", petak[a + 900][b + 900]);
  }
  return 0;
}
