#include<bits/stdc++.h>
#define ll long long
#define nmsl 0
using namespace std;
ll a[3005], b[3003], num;int T, n, ans, Q, l, r, x, y;
inline int find(int l, int r){
	x=a[l], y=b[l];
	for(int f(l+1); f<=r; f+=1){
		if(a[f]>x){x=a[f];}
		if(b[f]>y){y=b[f];}
	}
	return x*y;
}
signed 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 kk(0); kk<Q; kk+=1){
		scanf("%d%d", &l, &r);ans=0;
		for(int i(l); i<=r; i+=1){
			for(int j(i); j<=r; j+=1){
				ans+=find(i, j);
			}
		}
		//if(ans>N){ans-=N;}
		printf("%d\n", ans);
	}
	return nmsl;
}
//WA++

