#include<bits/stdc++.h>
using namespace std;
int t,n,q;
int a[100010],b[100010];
unsigned long long sum=0;
int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	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]);
	}
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		int l,r;
		sum=0;
		scanf("%d%d",&l,&r);
		for(int i=l;i<=r;i++){
			int maxa=0;
			int maxb=0;
			for(int j=i;j<=r;j++){
				if(a[j]>maxa){
					maxa=a[j];
				}
				if(b[j]>maxb){
					maxb=b[j];
				}
				sum+=(maxa*maxb);
			}
		}
		printf("%llu",sum);
		if(i!=q)printf("\n");
	}
	return 0;
}
