#include <bits/stdc++.h>

typedef unsigned long long int ull;

ull bit1[600000];
ull bit2[600000];
int size = 1;

using std::max;

void init(ull* arr, int cur, int pos, int l, int r, int val){
	if((l == r) && (l == pos)){
		arr[cur] = val;
		return;
	}
	arr[cur] = max(arr[cur], (ull)val);
	int mid = (l + r) / 2;
	if(pos <= mid){
		init(arr, cur * 2, pos, l, mid, val);
	}else{
		init(arr, cur * 2 + 1, pos, mid + 1, r, val);
	}
}

ull ask(ull* arr, int cur, int x, int y, int l, int r){
	if((x == l) && (y == r)){
		return arr[cur];
	}
	int mid = (l + r) / 2;
	if((x <= mid) && (y > mid)){
		ull ret1 = ask(arr, cur * 2, x, mid, l, mid);
		ull ret2 = ask(arr, cur * 2 + 1, mid + 1, y, mid + 1, r);
		return max(ret1, ret2);
	}else if(y <= mid){
		return ask(arr, cur * 2, x, y, l, mid);
	}else{
		return ask(arr, cur * 2 + 1, x, y, mid + 1, r);
	}
}

int main(){
	freopen("match.in", "r", stdin);
	freopen("match.out", "w", stdout);
	int T, n;
	scanf("%d%d", &T, &n);
	
	while(n > size) size <<= 1;
	int i, j;
	int val;
	for(i = 1; i <= size * 2; i++){
		bit1[i] = bit2[i] = 0;
	}
	
	for(i = 1; i <= n; i++){
		scanf("%d", &val);
		init(bit1, 1, i, 1, size, val);
	}
	
	for(i = 1; i <= n; i++){
		scanf("%d", &val);
		init(bit2, 1, i, 1, size, val);
	}
	
	int q;
	scanf("%d", &q);
	
	int l, r;
	
	for( ; q > 0; q--){
		ull ans = 0;
		scanf("%d%d", &l, &r);
		
		for(i = l; i <= r; i++){
			for(j = i; j <= r; j++){
				ans += ask(bit1, 1, i, j, 1, size) * ask(bit2, 1, i, j, 1, size);
			}
		}
		
		std::cout << ans;
		printf("\n");
	}
	
	return 0;
}

