#include <bits/stdc++.h>
using namespace std;
const int MAX = 100;
struct Mat {
  int ma[MAX][MAX];
  void clear() { memset(ma, 0, sizeof(ma)); }
} res[MAX];
int pow4[] = {1, 4, 16, 64, 256, 1024, 4096, 16384, 65536};
int mxsize;
int FourBit(int val) {
  for (int i = 0;; i++)
    if (pow4[i] > val) return i - 1;
}
void Expand(int x, int y, int val, Mat &a) {
  int tp = val / 4;
  if (x == 1)
    a.ma[x - 1][y] += tp * 2;
  else if (x > 1)
    a.ma[x - 1][y] += tp;
  if (y == 1)
    a.ma[x][y - 1] += tp * 2;
  else if (y > 1)
    a.ma[x][y - 1] += tp;
  if (x + 1 == mxsize) mxsize++;
  a.ma[x + 1][y] += tp;
  if (y + 1 == mxsize) mxsize++;
  a.ma[x][y + 1] += tp;
  a.ma[x][y] += val % 4;
}
Mat Update(Mat m) {
  Mat ans[2];
  int a = 0, b = 1, flag = 1, tp;
  ans[0] = m;
  while (flag) {
    ans[b].clear();
    flag = 0;
    for (int i = 0; i < mxsize; i++) {
      for (int j = 0; j < mxsize; j++) {
        if ((tp = ans[a].ma[i][j]) >= 4) {
          flag = 1;
          Expand(i, j, tp, ans[b]);
        } else {
          ans[b].ma[i][j] += tp;
        }
      }
    }
    a ^= 1;
    b ^= 1;
  }
  return ans[a];
}
Mat AddMat(Mat a, Mat b) {
  Mat c;
  c.clear();
  for (int i = 0; i < mxsize; i++)
    for (int j = 0; j < mxsize; j++) c.ma[i][j] = a.ma[i][j] + b.ma[i][j];
  return c;
}
void GetPow() {
  res[0].clear();
  res[0].ma[0][0] = 1;
  mxsize = 1;
  for (int i = 1; i <= 15; i++) {
    res[i] = Update(AddMat(res[i - 1], res[i - 1]));
  }
}
int main() {
  int n, m;
  GetPow();
  while (scanf("%d%d", &n, &m) != EOF) {
    Mat ans;
    ans.clear();
    for (int i = 0, st = n; st; st >>= 1, i++)
      if (st & 1) ans = AddMat(ans, res[i]);
    ans = Update(ans);
    for (int i = 0; i < m; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      if (x < 0) x = -x;
      if (y < 0) y = -y;
      if (x >= MAX || y >= MAX)
        printf("0\n");
      else
        printf("%d\n", ans.ma[x][y]);
    }
  }
  return 0;
}
