#include<bits/stdc++.h>
#define rr return
#define RS 500010
#define ull unsigned long long 
#define f(a,b,c) for(int c=a;c<=b;c++)
#define ff(a,b,c) for(int c=a;c>=b;c--)
using namespace std;
const int mod = 1e9+7;
#define gc getchar
int rd(){
	int v=1,w=0;
	char c=gc();
	while(c<'0'||c>'9'){
		if(c=='-') v=-1;
		c=gc();
	}
	while(c>='0'&&c<='9'){
		w=(w<<1)+(w<<3)+(c&15);
		c=gc();
	} rr v*w;
}
ull ksm(int a,int b){
	ull ans=1;
	while(b){
		if(b&1){
			ans=ans*a%mod;
		}
		a=a*a%mod;
		b>>=1;
	} rr ans;
}
int t,n,a[RS],b[RS],q,l,r;
signed main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	cin>>t>>n;
	f(1,n,i) a[i]=rd();
	f(1,n,i) b[i]=rd();
	cin>>q;
	while(q--){ ull ans=0;
		l=rd(); r=rd();
		f(l,r,i){
			f(i,r,j){
				int a1=0,b1=0;
				f(i,j,k){
					a1=max(a1,a[k]);
					b1=max(b1,b[k]);
				}
				ans+=a1*b1;
			}
		} cout<<ans<<endl;
	}
	rr 0;
}/*
0 2
2 1
1 2
1
1 2
*/