#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int N=3005;
int a[N],b[N],n;
ull val[N][N];
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++) {
		ull maxa=0,maxb=0;
		for (int j=i; j<=n; j++) {
			maxa=max(maxa,(ull)a[j]);
			maxb=max(maxb,(ull)b[j]);
			val[i][j]=maxa*maxb;
		}
	}	
	for (int i=1; i<=n; i++)
		for (int j=1; j<=n; j++)
			val[i][j]+=val[i][j-1];
	for (int i=1; i<=n; i++)
		for (int j=1; j<=n; j++)
			val[i][j]+=val[i-1][j];
	int q; scanf("%d",&q);
	while (q--) {
		int l,r; scanf("%d%d",&l,&r);
		printf("%llu\n",val[r][r]-val[l-1][r]-val[r][l-1]+val[l-1][l-1]);
	}
}
