#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll Mod=0; 
const int maxn=1e5+5;
int T,n,l,r,q;
ll a[maxn],b[maxn],res;
ll ans[505][505];
ll pow(ll a,int b)
{
	ll ans=1;
	while(b){
		if(b&1) ans*=a;
		a*=a;
		b>>=1;
	}
	return ans;
}
struct Node{
	int l,r;
	ll num;
}T1[maxn],T2[maxn];

void buildtree1(int u,int l,int r){
	T1[u].l=l;
	T1[u].r=r;
	if(l==r){
		T1[u].num=a[l];return;
	} 
	int mid=(l+r)>>1;
	buildtree1(u<<1,l,mid);
	buildtree1(u<<1|1,mid+1,r);
	T1[u].num=max(T1[u].num,T1[u<<1].num); 
	T1[u].num=max(T1[u].num,T1[u<<1|1].num); 
}

void buildtree2(int u,int l,int r){
	T2[u].l=l;
	T2[u].r=r;
	if(l==r){
		T2[u].num=b[l];return;
	} 
	int mid=(l+r)>>1;
	buildtree2(u<<1,l,mid);
	buildtree2(u<<1|1,mid+1,r);
	T2[u].num=max(T2[u].num,T2[u<<1].num); 
	T2[u].num=max(T2[u].num,T2[u<<1|1].num);
}

ll query1(int u,int l,int r){
	if(l<=T1[u].l && T1[u].r<=r){
		return T1[u].num;
	}
	ll res=0;
	int mid=(T1[u].l+T1[u].r)>>1;
	if(l<=mid) res=max(res,query1(u<<1,l,r));
	if(r>mid) res=max(res,query1(u<<1|1,l,r));
	return res;
}
ll query2(int u,int l,int r){
	if(l<=T2[u].l && T2[u].r<=r){
		return T2[u].num;
	}
	ll res=0;
	int mid=(T2[u].l+T2[u].r)>>1;
	if(l<=mid) res=max(res,query2(u<<1,l,r));
	if(r>mid) res=max(res,query2(u<<1|1,l,r));
	return res;
}

signed main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	scanf("%d%d",&T,&n);
	Mod=pow(2,64);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	buildtree1(1,1,n);
	for(int i=1;i<=n;i++){
		scanf("%d",&b[i]);
	}
	buildtree2(1,1,n);
	scanf("%d",&q);
	while(q--){
		scanf("%d%d",&l,&r);
		if(ans[l][r]) {
			printf("%lld\n",ans[l][r]);
		} 
		res=0;
		for(int i=l;i<=r;i++){
			for(int j=i;j<=r;j++){	
				res+=1ll*query1(1,i,j)*query2(1,i,j);
				//printf("%d %d %d %d\n",i,j,query1(1,i,j),query2(1,i,j));
				res=res%Mod;
				//printf("%d!!\n",res);
			}
		}
		printf("%lld\n",res);
		ans[l][r]=res;
	}
	return 0;
} 
