// what is matter? never mind.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define int long long
#define ull unsigned long long
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define mod 998244353
struct modint{
int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,modint b){return a.x==b.x;}
friend bool operator !=(modint a,modint b){return a.x!=b.x;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
vector<modint> fac,ifac,iv;
inline void initC(int n)
{
if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
int m=iv.size(); ++n;
if(m>=n)return;
iv.resize(n),fac.resize(n),ifac.resize(n);
For(i,m,n-1){
iv[i]=iv[mod%i]*(mod-mod/i);
fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
}
}
inline modint C(int n,int m){
if(m<0||n<m)return 0;
return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 800005
#define inf 0x3f3f3f3f
bool mbe;
int n,m;
struct P{
int x,y,id;
P(int xx=0,int yy=0){
x=xx,y=yy;
}
P&operator +=(P o){return x+=o.x,y+=o.y,*this;}
P&operator -=(P o){return x-=o.x,y-=o.y,*this;}
P&operator *=(int o){return x*=o,y*=o,*this;}
P&operator /=(int o){return x/=o,y/=o,*this;}
friend P operator +(P a,P b){return a+=b;}
friend P operator -(P a,P b){return a-=b;}
friend P operator *(P a,int b){return a*=b;}
friend P operator /(P a,int b){return a/=b;}
friend bool operator <(P a,P b){return a.x==b.x?a.y<b.y:a.x<b.x;}
friend ll operator *(P a,P b){return 1ll*a.x*b.y-1ll*a.y*b.x;} // cross
};
P a[maxn];
bool chk(P a,P b,P c,bool bo){
if(bo==1) return (b-a)*(c-a)>=0;
return (b-a)*(c-a)<=0;
}
#define N 300005
int res[N],id[N],xl[N],xr[N],yl[N],yr[N];
int tmp[N];
bool isok(P p,int i){
if(p.x<xl[i] || p.x>xr[i]) return 0;
if(xl[i]==xr[i]){
return p.x==xl[i] && p.y<=min(yl[i],yr[i]);
}
P p0=P(xl[i],yl[i]),p1=P(xr[i],yr[i]);
return (p1-p0)*(p-p0)>=0;
}
P line(int i){
return P(xr[i]-xl[i],yr[i]-yl[i]);
}
struct hull{
P st[maxn];
int tp,bo;
void add(P p){
while(tp>1 && chk(st[tp-1],st[tp],p,bo)) --tp;
st[++tp]=p;
}
int ask(int x){
// cout<<"ask "<<x<<" "<<tp<<"\n";
if(!tp) return -1;
if(tp<=1 ){
For(i,1,tp) if(isok(st[i],x)) return st[i].id;
return -1;
}
//For(i,1,tp) cout<<"chk "<<st[i].x<<" "<<x<<"\n";
// For(i,1,tp) if(isok(st[i],x)) return st[i].id;
if(bo==0){
int l=1,r=tp;
while(l<=r){
int mid=l+r>>1;
if(isok(st[mid],x)) return st[mid].id;
if(mid==1 || (st[mid-1]-st[mid])*(line(x))>0)l=mid+1;
else r=mid-1;
}
}else{
int l=1,r=tp;
while(l<=r){
int mid=l+r>>1;
if(isok(st[mid],x)) return st[mid].id;
if(mid==1 || (st[mid]-st[mid-1])*(line(x))<0)l=mid+1;
else r=mid-1;
}
}
return -1;
}
}H;
void solve(int l,int r,int idl,int idr){
if(idl>idr)return;
if(l==r){
For(_,idl,idr){
int i=id[_];
if(xl[i]<=a[l].x && xr[i]>=a[l].x && isok(a[l],i)) res[i]=a[l].id;
}
return;
}
int mid=l+r>>1;
vi o;
int tpl=idl,tpr=idr;
For(i,idl,idr){
if(xl[id[i]]<=a[mid].x && xr[id[i]]>=a[mid+1].x) o.pb(id[i]);//cout<<"mid "<<id[i]<<"\n";
else if(xr[id[i]]<a[mid+1].x) tmp[tpl++]=id[i];//cout<<"tol "<<id[i]<<"\n";
else tmp[tpr--]=id[i];//cout<<"tor "<<id[i]<<"\n";
}
// cout<<"solve "<<l<<" "<<r<<"\n";
// for(int x:o)cout<<x<<" "; cout<<"\n";
// cout<<"tpl,tpr "<<tpl<<" "<<tpr<<"\n";
bool hav46=0;
For(i,idl,tpl-1) id[i]=tmp[i];
For(i,tpr+1,idr) id[i]=tmp[i];
sort(o.begin(),o.end(),[&](int x,int y){
return xl[x]>xl[y];
});
int pos=0;
H.tp=0,H.bo=0;
Rep(i,mid,l){
while(pos<o.size() && xl[o[pos]]>a[i].x){
int x=o[pos]; ++pos;
if(res[x]==-1) res[x]=H.ask(x);
}
H.add(a[i]);
}
while(pos<o.size()){
int x=o[pos]; ++pos;
if(res[x]==-1) res[x]=H.ask(x);
}
sort(o.begin(),o.end(),[&](int x,int y){
return xr[x]<xr[y];
});
pos=0;
H.tp=0,H.bo=1;
For(i,mid+1,r){
while(pos<o.size() && xr[o[pos]]<a[i].x){
int x=o[pos]; ++pos;
if(res[x]==-1) res[x]=H.ask(x);
}H.add(a[i]);
}
while(pos<o.size()){
int x=o[pos]; ++pos;
if(res[x]==-1) res[x]=H.ask(x);
}
solve(l,mid,idl,tpl-1);
solve(mid+1,r,tpr+1,idr);
}
bool med;
signed main()
{
// freopen("data.in","r",stdin);
// freopen("my.out","w",stdout);
// cout<<(1.0*(&mbe-&med)/1024576.0)<<"\n";
n=read();
For(i,1,n)a[i].x=read(),a[i].y=read(),a[i].id=i;
sort(a+1,a+n+1);
m=read();
For(i,1,m){
xl[i]=read(),yl[i]=read();
xr[i]=read(),yr[i]=read();
if(xl[i]>xr[i]) swap(xl[i],xr[i]),swap(yl[i],yr[i]);
res[i]=-1;
id[i]=i;
}
solve(1,n,1,m);
For(i,1,m){
cout<<res[i]<<"\n";
}
return 0;
}
/*
10
5 7
6 6
8 3
2 2
4 2
3 5
7 6
10 4
1 5
9 3
1
3 7 4 8
*/