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

typedef unsigned long long ull;

const int MAX_N = 250010;
const int MAX_L = 40;

int T, n, q;
int a[MAX_N], b[MAX_N];
ull sta[MAX_N][MAX_L], stb[MAX_N][MAX_L];
int Log2[MAX_N];
//ull res[MAX_N][MAX_N];

void read(int &x){
	char c = getchar(); x = 0;
	while (!isdigit(c)) c = getchar();
	while ( isdigit(c)) x = x * 10 + (c ^ '0'), c = getchar();
	return;
}

ull querya(int l, int r){
	int len = r - l + 1, nxt = r - (1 << Log2[len]) + 1;
	return (ull) max(sta[l][Log2[len]], sta[nxt][Log2[len]]);
}

ull queryb(int l, int r){
	int len = r - l + 1, nxt = r - (1 << Log2[len]) + 1;
	return (ull) max(stb[l][Log2[len]], stb[nxt][Log2[len]]);
}

int main(){
	freopen("match.in", "r", stdin);
	freopen("match.out", "w", stdout);
	read(T); read(n);
	for (int i = 1; i <= n; i++){
		read(a[i]);
		sta[i][0] = (ull) a[i];
	}
	for (int i = 1; i <= n; i++){
		read(b[i]);
		stb[i][0] = (ull) b[i];
	}
	for (int i = 2; i <= n; i++){
		Log2[i] = Log2[i >> 1] + 1;
	}
	for (int i = 1; i <= Log2[n]; i++){
		for (int j = 1; j + (1 << i) - 1 <= n; j++){
			int nxt = j + (1 << (i - 1));
			sta[j][i] = max(sta[j][i - 1], sta[nxt][i - 1]);
			stb[j][i] = max(stb[j][i - 1], stb[nxt][i - 1]);
			//printf("sta[%d][%d] = %d\n", j, i, sta[j][i]);
		}
	}
	read(q);
	while (q--){
		int l, r; ull ans = 0;
		read(l); read(r);
		for (int i = l; i <= r; i++){
			for (int j = i; j <= r; j++){
				ull maxa = querya(i, j), maxb = queryb(i, j);
				//printf("i = %d j = %d: maxa = %llu maxb = %llu\n", i, j, maxa, maxb);
				ans = ans + maxa * maxb;
			}
		}
		printf("%llu\n", ans);
	}
	return 0;
}
