#include<bits/stdc++.h>
#define int 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--)
#define p(x) printf("%lld ",(x))
#define P() puts("")
using namespace std;


inline int read()
{
	char c=getchar();int x=0;bool f=0;
	while(!isdigit(c)) f^=!(c^45),c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;
	return x;
}

inline int diread()
{
	char c=getchar();int x=0;
	while(!isdigit(c)) c=getchar();
	x=(c^48);
	return x;
}

const int maxn=250050;
const int mod=998244353;

int n,T,a[maxn],b[maxn];

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 Q=read();
	while(Q--)
	{
		int ans=0;
		int l,r;
		l=read();r=read();
		For(q,l,r)
			For(p,q,r)
			{
				int ff1=0,ff2=0;
				For(i,q,p)
				{
					ff1=max(ff1,a[i]);
					ff2=max(ff2,b[i]);
				}
				ans+=ff1*ff2;
			}
		p(ans);P();
	}
	return 0;
}
