#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
typedef unsigned long long ll;
int T,n;
int a[3005],b[3005];
ll che[3005][3005],pre[3005][3005];
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]);
	}
	for(int i=1;i<=n;i++){
		int maxa=-1e9,maxb=-1e9;
		for(int j=i;j<=n;j++){
			maxa=max(maxa,a[j]);
			maxb=max(maxb,b[j]);
			che[i][j]=maxa*maxb;
		}
	}
	for(int i=1;i<=n;i++){
		pre[i][i-1]=0;
		for(int j=i;j<=n;j++){
			pre[i][j]=pre[i][j-1]+che[i][j];
		}
	}
//	for(int i=1;i<=n;i++){
//		for(int j=i;j<=n;j++){
//			printf("%d,%d=%llu\n",i,j,che[i][j]);
//		}
//	}
	int Q;
	scanf("%d",&Q);
	while(Q--){
		int l,r;
		scanf("%d%d",&l,&r);
		ll ans=0;
		for(int i=l;i<=r;i++){
			ans=ans+pre[i][r];
		}
		printf("%llu\n",ans);
	}
	return 0;
}
