#include <cstdio>
#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
const int N = 2e5 + 5e4 + 11;
int a[N], b[N];

#define max(a, b) ((a) > (b) ? (a) : (b))

int main(){
	freopen("match.in","r", stdin);
	freopen("match.out", "w", stdout);
	int T, n, Q;
	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);
	ull ans;
	int Ma, Mb, p, q;
	for(int i = 1; i <= Q; ++i){
		scanf("%d%d", &p, &q);
		ans = 0LL;
		for(int j = p; j <= q; ++j){
			for(int k = j; k <= q; ++k){
				Ma = a[j];
				Mb = b[j];
				for(int l = j + 1; l <= k; ++l)
				    Ma = max(Ma, a[l]),
				    Mb = max(Mb, b[l]);
				ans += ((ull)(Ma) * (ull)(Mb));
			}
		}printf("%lld\n", ans);
	}
	return 0;
}
