#include <bits/stdc++.h>

using std::max;

const int N=25e4+5;

typedef unsigned long long ull;

ull a[N],b[N];

std::map<std::pair<int,int>,ull> mp;

int main()
{
	freopen("match.in","r",stdin);freopen("match.out","w",stdout);
	
	int T,n;scanf("%d%d",&T,&n);for(int i=1;i<=n;++i)scanf("%llu",a+i);for(int i=1;i<=n;++i)scanf("%llu",b+i);
	int Q;scanf("%d",&Q);
	while(Q--)
	{
		int l,r;scanf("%d%d",&l,&r);
		if(mp[std::make_pair(l,r)]){printf("%llu\n",mp[std::make_pair(l,r)]);continue;}
		ull ans=0;
		for(int p=l;p<=r;++p)
		{
			ull ax=a[p],bx=b[p];
			for(int q=p;q<=r;++q)
			{
				ax=max(ax,a[q]);bx=max(bx,b[q]);
				ans+=ax*bx;
			}
		}
		printf("%llu\n",ans);
		mp[std::make_pair(l,r)]=ans;
	}
	
	fclose(stdin);fclose(stdout);
	return 0;
}

/*
0 2
2 1
1 2
2
1 2
1 2

*/