#include<bits/stdc++.h>
#define int unsigned long long
using namespace std;

inline int read(){
	int n=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
	while(isdigit(ch)){n=n*10+ch-'0';ch=getchar();}
	return n*f;
}
int Max(int a,int b){
	return a>b?a:b;
}
const int N=3e3+10;
int n,T,q;
int a[N],b[N],lg[N];
int sta[15][N],stb[15][N];
int query1(int l,int r){
	int len=lg[r-l+1];
	return Max(sta[len][l],sta[len][r-(1<<len)+1]);
}
int query2(int l,int r){
	int len=lg[r-l+1];
	return Max(stb[len][l],stb[len][r-(1<<len)+1]);
}
signed main(){	
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	T=read(),n=read();
	for(int i=2;i<=n;i++) lg[i]=lg[i>>1]+1;
	for(int i=1;i<=n;i++) a[i]=read(),sta[0][i]=a[i];
	for(int i=1;i<=n;i++) b[i]=read(),stb[0][i]=b[i];
	for(int i=1;i<=lg[n];i++){
		for(int j=1;j+(1<<i)-1<=n;j++){
			sta[i][j]=Max(sta[i-1][j],sta[i-1][j+(1<<(i-1))]);
			stb[i][j]=Max(stb[i-1][j],stb[i-1][j+(1<<(i-1))]);
		}
	}
	q=read();
	while(q--){
		int ans=0;
		int l=read(),r=read();
		for(int p=l;p<=r;p++){
			for(int q=p;q<=r;q++){
				ans+=query1(p,q)*query2(p,q);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}
/*
0 2
2 1
1 2
1
1 2
*/