#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std ;
using ll = long long ;
using ull = unsigned long long ;
ull *mem ;
const ull ONES = (ull)(-1LL) ;
void relimit(vector<ll> &c, vector<ll> &c1, vector<ll> &c2, map<ll, ll> &xmap) {
   sort(c.begin(), c.end()) ;
   // locate boundary wall pair:  BB....F
   ll fc = c[0] - 6 ;
   ll lc = c[c.size()-1] + 5 ;
   vector<ll> probes = c1 ;
   probes.insert(probes.end(), c2.begin(), c2.end()) ;
   sort(probes.begin(), probes.end()) ;
   probes.resize(unique(probes.begin(), probes.end()) - probes.begin()) ;
   for (auto v: probes) {
      fc = min(fc, v-2) ;
      lc = max(lc, v+1) ;
   }
   c.insert(c.begin(), fc+1) ;
   c.insert(c.begin(), fc) ;
   c.push_back(lc) ;
   c.push_back(lc+1) ;
   ll bigc = fc ;
   ll smc = 0 ;
   int pat = 0 ;
   int cat = 1 ;
   ll nbigc, nsmc ;
   vector<ll> newv ;
   while (1) {
      xmap[bigc] = smc ;
      newv.push_back(smc) ;
      if (cat >= (int)c.size())
         break ;
      nbigc = c[cat++] ;
      if (nbigc - bigc > 7)
         nsmc = smc + 5 + (nbigc - bigc + 3) % 4 ;
      else
         nsmc = smc + nbigc - bigc ;
      while (pat < (int)probes.size() && probes[pat] < nbigc) {
         xmap[probes[pat]] = smc + 1 + (probes[pat] - bigc + 3) % 4 ;
         pat++ ;
      }
      bigc = nbigc ;
      smc = nsmc ;
   }
   swap(newv, c) ;
}
int dx[] = {-2, -2, -1, -1,  1, 1,  2, 2 } ;
int dy[] = {-1,  1, -2,  2, -2, 2, -1, 1 } ;
int nomoves(ll x, ll y, map<ll, ll> &xb, map<ll, ll> &yb) {
   for (int i=0; i<8; i++) {
      ll x2 = x + dx[i] ;
      ll y2 = y + dy[i] ;
      if (xb.find(x2) == xb.end() && yb.find(y2) == yb.end())
         return 0 ;
   }
   return 1 ;
}
int main(int argc, char *argv[]) {
   int n, q ;
   cin >> n >> q ;
   if (n == 0) {
      for (int i=0; i<q; i++)
         cout << 1 << endl ;
      exit(0) ;
   }
   vector<ll> xr(n), yr(n) ;
   for (int i=0; i<n; i++)
      cin >> xr[i] >> yr[i] ;
   vector<ll> xs(q), ys(q), xe(q), ye(q) ;
   vector<char> solved(q) ;
   for (int i=0; i<q; i++)
      cin >> xs[i] >> ys[i] >> xe[i] >> ye[i] ;
   map<ll, ll> xrs, yrs ;
   for (auto v: xr)
      xrs[v] = v ;
   for (auto v: yr)
      yrs[v] = v ;
   // mod4 only holds if we can move at all,
   // so check before coordinate compression
   for (int i=0; i<q; i++)
      if (xs[i] == xe[i] && ys[i] == ye[i])
         solved[i] = 3 ;
      else if (nomoves(xs[i], ys[i], xrs, yrs) || nomoves(xe[i], ye[i], xrs, yrs))
         solved[i] = 1 ;
   relimit(xr, xs, xe, xrs) ;
   relimit(yr, ys, ye, yrs) ;
   ll w = xr[xr.size()-1] + 1 ;
   ll h = yr[yr.size()-1] + 1 ;
   ll ww = (w + 63) >> 6 ;
   mem = (ull *)calloc(ww * sizeof(ull), h) ;
   for (auto v: yr)
      for (int i=0; i<ww; i++)
         mem[v * ww + i] = ONES ;
   for (auto v: xr)
      for (int i=0; i<h; i++)
         mem[i * ww + (v >> 6)] |= 1LL << (v & 63) ;
   vector<pair<ll, ll>> lev0, lev1, lev2 ;
   for (int i=0; i<q; i++) {
      if (solved[i])
         continue ;
      ll thispart = 0 ;
      lev0.clear() ;
      lev1.clear() ;
      lev2.clear() ;
      ll x1 = xrs[xs[i]] ;
      ll y1 = yrs[ys[i]] ;
      lev1.push_back({xrs[xs[i]], yrs[ys[i]]}) ;
      mem[y1 * ww + (x1 >> 6)] |= 1LL << (x1 & 63) ;
      for (int d=1; ; d++) {
         if (lev1.size() == 0)
            break ;
         thispart += lev1.size() ;
         for (auto [x, y]: lev1) {
            for (int dd=0; dd<8; dd++) {
               auto x2 = x + dx[dd] ;
               auto y2 = y + dy[dd] ;
               if (0 == ((mem[y2 * ww + (x2 >> 6)] >> (x2 & 63)) & 1)) {
                  mem[y2 * ww + (x2 >> 6)] |= 1LL << (x2 & 63) ;
                  lev2.push_back({x2, y2}) ;
               }
            }
         }
         swap(lev0, lev1) ;
         swap(lev1, lev2) ;
         lev2.clear() ;
      }
      if (argc > 1)
         cerr << "Part " << thispart << endl ;
      for (int j=i; j<q; j++) {
         if (solved[j])
            continue ;
         x1 = xrs[xs[j]] ;
         y1 = yrs[ys[j]] ;
         ll x2 = xrs[xe[j]] ;
         ll y2 = yrs[ye[j]] ;
         int sf = ((mem[y1 * ww + (x1 >> 6)] >> (x1 & 63)) & 1) ;
         int se = ((mem[y2 * ww + (x2 >> 6)] >> (x2 & 63)) & 1) ;
         if (sf || se) {
            if (sf && se) {
               solved[j] = 3 ;
            } else {
               solved[j] = 1 ;
            }
         }
      }
   }
   for (auto v: solved)
      cout << (v >> 1) << endl ;
}
