#include<bits/stdc++.h>
#define fori(i,a,b) for(i=a;i<=b;i++)
#define ford(i,a,b) for(i=a;i>=b;i--)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
using namespace std;
const int N=1e6+5;
ull n,l1,r1,i,j,Q,a[N],b[N],maxa,maxb,ans;
int main()
{
	freopen("match.in","r",stdin); freopen("match.out","w",stdout);
	cin>>n>>n;
	fori(i,1,n) scanf("%lld",&a[i]);
	fori(i,1,n) scanf("%lld",&b[i]);
	cin>>Q;
	while (Q--)
	{
		scanf("%lld%lld",&l1,&r1);
		ans=0;
		fori(i,l1,r1)
		{
			maxa=a[i];
			maxb=b[i];
			ans+=a[i]*b[i];
			fori(j,i+1,r1)
			{
				maxa=max(a[j],maxa);
				maxb=max(b[j],maxb);
				ans+=maxa*maxb;
			}
		}
		printf("%lld\n",ans);
	}
}