#include <iostream>
using namespace std;

typedef long long LL;

int n, m;
int a[100], b[100];

int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	int T, Q;
	cin >> T >> n;
	for (int i = 1;i <= n; ++ i) cin >> a[i];
	for (int i = 1;i <= n; ++ i) cin >> b[i];
	cin >> Q;
	while (Q --){
		int l, r;
		cin >> l >> r;
		LL ans = 0;
		for (int p = l;p <= r; ++ p)
			for (int q = p;q <= r; ++ q){
				int ida = 0, idb = 0;
				for (int i = p;i <= q; ++ i){
					if (a[i] > a[ida])
						ida = i;
					if (b[i] > b[idb])
						idb = i;
				}
//				cout << a[ida] << " " << b[idb] << endl;
				ans += 1LL * a[ida] * b[idb];
			}
		printf("%lld\n", ans);
	}
	return 0;
}