#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[250005];
ll b[250005];
ll ma[250005];
ll mb[250005];
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("%d",&a[i]);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&b[i]);
	}
	for(int i=1;i<=n;i++){
		ma[i]=max(ma[i-1],a[i]);
		mb[i]=max(mb[i-1],b[i]);
	}
	int q;
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		int l,r;
		scanf("%d%d",&l,&r);
		ll ans=0;
		for(int j=l;j<=r;j++){
			for(int k=j;k<=r;k++){
				if(ma[j]!=ma[k]){
					if(mb[j]!=mb[k]){
						ans+=mb[k]*ma[k];
					}
					else{
						ll bb=-1;
						for(int l=j;l<=k;l++){
							bb=max(bb,b[l]);
						}
						ans+=bb*ma[k];
					}
				}
				else{
					if(mb[j]!=mb[k]){
						ll aa=-1;
						for(int l=j;l<=k;l++){
							aa=max(aa,a[l]);
						}
						ans+=mb[k]*aa;
					}
					else{
						ll bb=-1;
						ll aa=-1;
						for(int l=j;l<=k;l++){
							bb=max(bb,b[l]);
							aa=max(aa,a[l]);
						}
						ans+=bb*aa;
					}
				}
			}
		}
		printf("%lld\n",ans);
	}
	cout<<endl;
	fclose(stdin);
	fclose(stdout);
	return 0;
}

