#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+10, M = 3e3+2, OO = 0x3f3f3f3f;
int t, n, u, v, c,q;
int vis[N];
vector<int>vi;
int bs(int x,vector<int>v){
int low=0,high=v.size()-1,med;
while(low<high){
med=(low+high+1)/2;
if(v[med]<=x) low=med;
else high=med-1;
}
return v[low];
}
int main(){
cin>>t;
while(t--){
int maxi=0;
vector<int>v;
cin>>n>>q;
for(int i=0;i<n;++i){
int x,y; cin>>x>>y;
v.push_back(x);
//mp[{x,y}]=1;
maxi=max(maxi,x);
}
sort(v.begin(),v.end());
while(q--){
int x,y,nx,ny; cin>>x>>y>>nx>>ny;
if(n==0){
cout<<abs(nx-x) <<"\n";
continue;
}
ll ans=0;
int dis1=abs((*lower_bound(v.begin(),v.end(),x)));
int dis2=abs(bs(x,v)-x);
// cout<<dis2<<" ";
ans+=min(dis1,dis2);
//cout<<ans;
dis1=abs((*lower_bound(v.begin(),v.end(),nx))-nx);
//cout<<dis1<<" ";
dis2=abs(bs(nx,v)-nx);
//cout<<dis2;
ans+=min(dis1,dis2);
cout<<min((ll)abs(nx-x),ans)<<"\n";
}
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnR5cGVkZWYgbG9uZyBsb25nIGxsOwpjb25zdCBpbnQgTiA9IDFlNSsxMCwgTSA9IDNlMysyLCBPTyA9IDB4M2YzZjNmM2Y7CmludCB0LCBuLCB1LCB2LCBjLHE7CmludCB2aXNbTl07CnZlY3RvcjxpbnQ+dmk7CmludCBicyhpbnQgeCx2ZWN0b3I8aW50PnYpewogICAgaW50IGxvdz0wLGhpZ2g9di5zaXplKCktMSxtZWQ7CiAgICB3aGlsZShsb3c8aGlnaCl7CiAgICAgICAgbWVkPShsb3craGlnaCsxKS8yOwogICAgICAgIGlmKHZbbWVkXTw9eCkgbG93PW1lZDsKICAgICAgICBlbHNlIGhpZ2g9bWVkLTE7CgogICAgfQogICAgcmV0dXJuIHZbbG93XTsKfQppbnQgbWFpbigpewogICAgY2luPj50OwogICAgd2hpbGUodC0tKXsKICAgIAlpbnQgbWF4aT0wOwogICAgICAgIHZlY3RvcjxpbnQ+djsKICAgICAgICBjaW4+Pm4+PnE7CiAgICAgICAgZm9yKGludCBpPTA7aTxuOysraSl7CiAgICAgICAgICAgIGludCB4LHk7IGNpbj4+eD4+eTsKICAgICAgICAgICAgdi5wdXNoX2JhY2soeCk7CiAgICAgICAgICAgIC8vbXBbe3gseX1dPTE7CiAgICAgICAgICAgIG1heGk9bWF4KG1heGkseCk7CiAgICAgICAgfQogICAgICAgIAogICAgICAgIHNvcnQodi5iZWdpbigpLHYuZW5kKCkpOwogICAgICAgIHdoaWxlKHEtLSl7CiAgICAgICAgCWludCB4LHksbngsbnk7IGNpbj4+eD4+eT4+bng+Pm55OwogICAgICAgIAlpZihuPT0wKXsKICAgICAgICAJCWNvdXQ8PGFicyhueC14KSA8PCJcbiI7CiAgICAgICAgCQljb250aW51ZTsKICAgICAgICAJfQogICAgICAgICAgICBsbCBhbnM9MDsKICAgICAgICAgICAgCiAgICAgICAgICAgIGludCBkaXMxPWFicygoKmxvd2VyX2JvdW5kKHYuYmVnaW4oKSx2LmVuZCgpLHgpKSk7CiAgICAgICAgICAgIGludCBkaXMyPWFicyhicyh4LHYpLXgpOwogICAgICAgICAgIC8vIGNvdXQ8PGRpczI8PCIgIjsKICAgICAgICAgICAgYW5zKz1taW4oZGlzMSxkaXMyKTsKICAgICAgICAgICAgLy9jb3V0PDxhbnM7CiAgICAgICAgICAgIGRpczE9YWJzKCgqbG93ZXJfYm91bmQodi5iZWdpbigpLHYuZW5kKCksbngpKS1ueCk7CiAgICAgICAgICAgIC8vY291dDw8ZGlzMTw8IiAiOwogICAgICAgICAgICBkaXMyPWFicyhicyhueCx2KS1ueCk7CiAgICAgICAgICAgIC8vY291dDw8ZGlzMjsKICAgICAgICAgICAgYW5zKz1taW4oZGlzMSxkaXMyKTsKICAgICAgICAgICAgY291dDw8bWluKChsbClhYnMobngteCksYW5zKTw8IlxuIjsKICAgICAgICB9CgogICAgfQoKfQ==