#include<bits/stdc++.h>
#define int long long
using namespace std;
int T,n,Q;
int a[100086],b[100086];
//const int mod=pow(2,64);

inline int read(){
	int flag=1,sum=0;
	char ch;
	while(!isdigit(ch)){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		sum=(sum<<3)+(sum<<1)+(ch^48);
		ch=getchar();
	}
	return flag*sum;
}


signed main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	
	T=read(); n=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
	}
	for(int j=1;j<=n;j++){
		b[j]=read();
	}
	Q=read();
	while(Q--){
		int l,r;
		unsigned long long ans=0;
		l=read(); r=read();
		for(int p=l;p<=r;p++){
			for(int q=p;q<=r;q++){
				int max_a=0,max_b=0;
				for(int i=p;i<=q;i++){
					max_a=max(max_a,a[i]);
					max_b=max(max_b,b[i]);
				}
				ans+=max_a*max_b;
//				ans%=mod;
			}
		}
		cout<<ans<<endl;
	}
	
	return 0;
}