#include<bits/stdc++.h>
#define int unsigned long long
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rep(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int maxn=3010;
inline int read()
{
	int x=0,f=1;char c;
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-f;
	for(;isdigit(c);c=getchar()) x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
int T,n,a[maxn],b[maxn];
struct segment_tree
{
	int mx[maxn<<2];
	#define lson l,mid,rt<<1
	#define rson mid+1,r,rt<<1|1
	inline void build(int *a,int l,int r,int rt)
	{
		if(l==r)
			return void(mx[rt]=a[l]);
		int mid=(l+r)>>1;
		build(a,lson),build(a,rson);
		mx[rt]=max(mx[rt<<1],mx[rt<<1|1]);
	}
	inline int query(int L,int R,int l,int r,int rt)
	{
		if(L<=l&&r<=R)
			return mx[rt];
		int mid=(l+r)>>1,ans=0;
		if(L<=mid) ans=max(ans,query(L,R,lson));
		if(R>mid) ans=max(ans,query(L,R,rson));
		return ans;
	}
}t1,t2;
#define root 1,n,1
signed main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	T=read(),n=read();
	For(i,1,n) a[i]=read();
	For(i,1,n) b[i]=read();
	int sq=read();
	t1.build(a,root),
	t2.build(b,root);
	while(sq--)
	{
		int l=read(),r=read();
		int maxa=0,maxb=0,ans=0;
		For(p,l,r)
			For(q,p,r)
			{
				maxa=t1.query(p,q,root),
				maxb=t2.query(p,q,root);
				ans=(ans+maxa*maxb);
			}
		printf("%llu\n",ans);
	}
	return 0;
}
