#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAXN = 250005;
const int INF = 2e9+5;
int a[MAXN],b[MAXN];
int l[MAXN];
int sta[MAXN][20],stb[MAXN][20];
int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	int t,n;
	scanf("%d%d",&t,&n);
	l[1]=0;l[2]=1;
	for(int i=3;i<=n;i++) l[i]=l[i/2]+1;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sta[i][0]=a[i];
	}
	for(int i=1;i<=n;i++){
		cin>>b[i];
		stb[i][0]=b[i];
	}
	for(int j=1;j<=20;j++){
		for(int i=1;i+(1<<j)-1<=n;i++){
			sta[i][j]=max(sta[i][j-1],sta[i+(1<<(j-1))][j-1]);
			stb[i][j]=max(stb[i][j-1],stb[i+(1<<(j-1))][j-1]);
		}
	}
	int qu;
	scanf("%d",&qu);
	while(qu--){
		int lt,r;
		ll ans=0;
		scanf("%d%d",&lt,&r);
		for(int p=lt;p<=r;p++){
			for(int q=p;q<=r;q++){
				int s=l[q-p+1];
				ans+=max(sta[p][s],sta[q-(1<<s)+1][s])*max(stb[p][s],stb[q-(1<<s)+1][s]);
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}

