import java.io.*;
import java.util.*;
public class loneknight_xiaowuc1 {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer(br.readLine());
    int n = Integer.parseInt(st.nextToken());
    int q = Integer.parseInt(st.nextToken());
    int[] xrook = new int[n];
    int[] yrook = new int[n];
    for(int i = 0; i < n; i++) {
      st = new StringTokenizer(br.readLine());
      xrook[i] = Integer.parseInt(st.nextToken());
      yrook[i] = Integer.parseInt(st.nextToken());
    }
    int[] xseg = getSegs(xrook);
    int[] yseg = getSegs(yrook);
    dsupar = new int[4 * xseg.length * yseg.length];
    Arrays.fill(dsupar, -1);
    dsusz = new int[4 * xseg.length * yseg.length];
    Arrays.fill(dsusz, 1);
    for(int i = 0; i < xseg.length; i+=2) for(int j = 0; j < yseg.length; j+=2) {
      int xid = i / 2;
      int yid = j / 2;
      for(int sx = xseg[i]; sx < xseg[i] + 4 && sx <= xseg[i+1]; sx++) {
        for(int sy = yseg[j]; sy < yseg[j] + 4 && sy <= yseg[j+1]; sy++) {
          int xoffset = (sx - xseg[i]) % 4;
          int yoffset = (sy - yseg[j]) % 4;
          for(int k = 0; k < 8; k++) {
            int nx = sx + dx[k];
            int ny = sy + dy[k];
            int nxid = -1;
            int nxoffset = -1;
            if(nx >= xseg[i] && nx <= xseg[i+1]) {
              nxid = xid;
              nxoffset = (nx - xseg[i])%4;
            }
            else if(nx > xseg[i+1]) {
              if(i+2 < xseg.length && nx >= xseg[i+2]) {
                nxid = xid + 1;
                nxoffset = (nx - xseg[i+2])%4;
              }
              else continue;
            }
            else if(nx < xseg[i]) {
              if(i > 0 && nx <= xseg[i-1]) {
                nxid = xid - 1;
                nxoffset = (nx - xseg[i-2])%4;
              }
              else continue;
            }
            else throw new RuntimeException();
            int nyid = -1;
            int nyoffset = -1;
            if(ny >= yseg[j] && ny <= yseg[j+1]) {
              nyid = yid;
              nyoffset = (ny - yseg[j])%4;
            }
            else if(ny > yseg[j+1]) {
              if(j+2 < yseg.length && ny >= yseg[j+2]) {
                nyid = yid + 1;
                nyoffset = (ny - yseg[j+2])%4;
              }
              else continue;
            }
            else if(ny < yseg[j]) {
              if(j > 0 && ny <= yseg[j-1]) {
                nyid = yid - 1;
                nyoffset = (ny - yseg[j-2])%4;
              }
              else continue;
            }
            else throw new RuntimeException();

            merge(
              16 * (xid * yseg.length/2 + yid) + 4 * xoffset + yoffset,
              16 * (nxid * yseg.length/2 + nyid) + 4 * nxoffset + nyoffset
            );
          }
        }
      }
    }
    PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    while(q-- > 0) {
      st = new StringTokenizer(br.readLine());
      int xa = Integer.parseInt(st.nextToken());
      int ya = Integer.parseInt(st.nextToken());
      int xb = Integer.parseInt(st.nextToken());
      int yb = Integer.parseInt(st.nextToken());
      int xi = Arrays.binarySearch(xseg, xa);
      if(xi < 0) xi = -xi-1;
      if(xi%2 != 0) xi--;
      int axid = xi / 2;
      int axoffset = (xa - xseg[xi]) % 4;
      xi = Arrays.binarySearch(xseg, xb);
      if(xi < 0) xi = -xi-1;
      if(xi%2 != 0) xi--;
      int bxid = xi / 2;
      int bxoffset = (xb - xseg[xi]) % 4;

      int yi = Arrays.binarySearch(yseg, ya);
      if(yi < 0) yi = -yi-1;
      if(yi%2 != 0) yi--;
      int ayid = yi / 2;
      int ayoffset = (ya - yseg[yi]) % 4;
      yi = Arrays.binarySearch(yseg, yb);
      if(yi < 0) yi = -yi-1;
      if(yi%2 != 0) yi--;
      int byid = yi / 2;
      int byoffset = (yb - yseg[yi]) % 4;

      int lid = 16 * (axid * yseg.length/2 + ayid) + 4 * axoffset + ayoffset;
      int rid = 16 * (bxid * yseg.length/2 + byid) + 4 * bxoffset + byoffset;
      if(lid == rid) {
        int sz = dsusz[find(lid)];
        pw.println(sz > 1 ? 1 : 0);
      }
      else {
        pw.println(find(lid) == find(rid) ? 1 : 0);
      }
    }
    pw.close();
  }
  static int[] dsupar, dsusz;
  private static int find(int x) {
    if(dsupar[x] < 0) return x;
    return dsupar[x] = find(dsupar[x]);
  }
  private static void merge(int x, int y) {
    x = find(x);
    y = find(y);
    if(x != y) {
      dsupar[x] = y;
      dsusz[y] += dsusz[x];
    }
  }
  private static int[] getSegs(int[] coords) {
    Arrays.sort(coords);
    int numsegs = 2;
    for(int i = 1; i < coords.length; i++) {
      if(coords[i] > coords[i-1] + 1) numsegs++;
    }
    int[] ret = new int[2*numsegs];
    ret[0] = (int)-1.01e9;
    ret[1] = coords[0]-1;
    int idx = 1;
    for(int i = 1; i < coords.length; i++) {
      if(coords[i] > coords[i-1] + 1) {
        ret[2*idx] = coords[i-1] + 1;
        ret[2*idx+1] = coords[i] - 1;
        idx++;
      }
    }
    ret[2*idx] = coords[coords.length-1]+1;
    ret[2*idx+1] = (int)1.01e9;
    return ret;
  }
  static int[] dx = new int[]{-2,-2,-1,-1,1,1,2,2};
  static int[] dy = new int[]{-1,1,-2,2,-2,2,-1,1};
}