#include<bits/stdc++.h>
#define mod 18446744073709551616
using namespace std;
int t,n;
int a[250001],b[250001];
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
inline int amax(int l,int r){
	int a1[250001];
	for(int i=1;i<=n;++i) a1[i]=a[i];
	sort(a1+l,a1+r+1);
	return a1[r];
}
inline int bmax(int l,int r){
	int b1[250001];
	for(int i=1;i<=n;++i) b1[i]=b[i];
	sort(b1+l,b1+r+1);
	return b1[r];
}
int 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 i=1;i<=n;++i) b[i]=read();
	int q=read();
	for(int i=1;i<=q;++i){
		int l=read(),r=read();
		long long ans=0;
		for(int j=l;j<=r;++j){
			for(int p=j;p<=r;++p){
				ans+=amax(j,p)*bmax(j,p);
			}
		}
		cout<<ans<<endl;
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}