#include <bits/stdc++.h>
#define int long long
#define ll long long
#define ri register
#define in inline
#define INF 0x3f3f3f3f
using namespace std;
const int N=3e5+10;
int a[N],b[N];
int T,n;
signed main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	cin >> T >> n;
	for(int i=1;i<=n;i++) cin >> a[i];
	for(int i=1;i<=n;i++) cin >> b[i];
	int Q;
	cin >> Q;
	while(Q--){
		int ans=0;
		int l,r;
		cin >> l >> r;
		for(int p=l;p<=r;p++){
			for(int q=p;q<=r;q++){
				int maxa=-INF,maxb=-INF;
				for(int k=p;k<=q;k++){
					maxa=max(maxa,a[k]);
					maxb=max(maxb,b[k]);
				}
				ans=ans+(maxa*maxb);
			}
		}
		cout << ans;
	}
}