#include<bits/stdc++.h>

using namespace std;

typedef unsigned long long ll;

const int MAXN = 250010;

int T,n,a[MAXN],b[MAXN];
int Va[MAXN << 2],Vb[MAXN << 2];

void builda(int l, int r, int x){
	if(l == r){
		Va[x] = a[l];
		return ;
	}
	int m = (l + r) >> 1;
	builda(l, m, x << 1);
	builda(m + 1, r, (x << 1) + 1);
	Va[x] = max(Va[x << 1],Va[(x << 1) + 1]);
	return ;
}

void buildb(int l, int r, int x){
	if(l == r){
		Vb[x] = b[l];
		return ;
	}
	int m = (l + r) >> 1;
	buildb(l, m, x << 1);
	buildb(m + 1, r, (x << 1) + 1);
	Vb[x] = max(Vb[x << 1],Vb[(x << 1) + 1]);
	return ;
}

ll querya(int l, int r, int s, int t, int x){
	if(l <= s && t <= r) return Va[x];
	int m = (s + t) >> 1;
	ll res = 0;
	if(l <= m) res = max(res, querya(l, r, s, m, x << 1));
	if(r > m) res = max(res, querya(l, r, m + 1, t, (x << 1) + 1));
	return res;
}

ll queryb(int l, int r, int s, int t, int x){
	if(l <= s && t <= r) return Vb[x];
	int m = (s + t) >> 1;
	ll res = 0;
	if(l <= m) res = max(res, queryb(l, r, s, m, x << 1));
	if(r > m) res = max(res, queryb(l, r, m + 1, t, (x << 1) + 1));
	return res;
}

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]);
	}
	builda(1, n, 1);
	buildb(1, n, 1);
	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++){
			for(int j = i;j <= r;j++){
				ll ma = querya(i, j, 1, n, 1),mb = queryb(i, j, 1, n, 1);
				ans += ma * mb;
//				printf("%d %d:%llu * %llu = %llu\n",i,j,ma,mb,ma * mb);
			}
		}
		printf("%llu\n",ans);
	}
	return 0;
}
