//I love Zhang Shuhao
//i want AC t1!!
//use unsigned ll
//20pts
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;

int n;
unsigned long long a[3010],b[3010],f[3010][3010];

int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	int T,Q;
	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]);
	}
	for (int i=1;i<=n;++i){
		unsigned long long maxa=0,maxb=0;
		for (int j=i;j<=n;++j){
			if (a[j]>maxa) maxa=a[j];
			if (b[j]>maxb) maxb=b[j];
			f[i][j]=maxa*maxb;
		}
	}
//	for (int i=1;i<=n;++i){
//		for (int j=1;j<=n;++j){
//			cout<<f[i][j]<<" ";
//		}cout<<endl;
//	}
	for (int i=1;i<=n;++i){
		for (int j=1;j<=n;++j){
			f[i][j]=f[i][j-1]+f[i][j];
		}
	}
	for (int j=1;j<=n;++j){
		for (int i=1;i<=n;++i){
			f[i][j]=f[i-1][j]+f[i][j];
		}
	}
//	for (int i=1;i<=n;++i){
//		for (int j=1;j<=n;++j){
//			cout<<f[i][j]<<" ";
//		}cout<<endl;
//	}
	scanf("%d",&Q);
	while (Q--){
		int l,r;
		scanf("%d%d",&l,&r);
		printf("%llu\n",f[r][r]-f[l-1][r]-f[r][l-1]+f[l-1][l-1]);
	}
	fclose(stdin);fclose(stdout);
	return 0;
}
