#include<iostream>
#include<cstdio>
#define ll unsigned long long

using namespace std;
ll sum[3005][3005],fang[3005][3005],shu[3005][3005],all[3005][3005],san[3005][3005];
int T,n,Q;
ll a[250005],b[250005];
ll Mod;
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	scanf("%d%d",&T,&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&b[i]);
	}
	for(int i=1;i<=n;i++){
		ll maxa=a[i],maxb=b[i];
	//	fang[i][i]
//		san[i][i]
		for(int j=i;j<=n;j++){
			maxa=max(maxa,a[j]);
			maxb=max(maxb,b[j]);
			sum[i][j]=maxa*maxb;
			fang[i][j]=fang[i-1][j]+sum[i][j];
			shu[i][j]=shu[i][j-1]+sum[i][j];
			all[i][j]=all[i-1][j]+shu[i][j];
	//		qz[i][j]=sum[i][j]+qz[i][j-1]+qz[i-1][j]-qz[i-1][j-1];
		}
		san[i][i]=san[i-1][i-1]+fang[i][i];
	}
	scanf("%d",&Q);
	for(int i=1;i<=Q;i++){
		int l,r;
		scanf("%d%d",&l,&r);
		cout<<san[r][r]-all[l-1][r]<<endl;
	}
	return 0;
}