#include<bits/stdc++.h>
#define ll long long

using namespace std;

const int N = 5e5 + 10;

struct node{
	int l, r;
	ll ma;
}tr1[N << 2], tr2[N << 2];

int n;
int a[N], b[N], res = 0;

inline int ls(int u){return u << 1;}
inline int rs(int u){return u << 1 | 1;}
inline ll jg(ll x, ll y){return x > y ? x : y;}

void pushup1(int u){
	tr1[u].ma = jg(tr1[rs(u)].ma, tr1[ls(u)].ma);
}

void build1(int u, int l, int r){
	if(l == r){
		tr1[u] = {l, r, a[l]};
	}
	else{
		tr1[u] = {l, r};
		int mid = l + r >> 1;
		build1(ls(u), l, mid);
		build1(rs(u), mid + 1, r);
		pushup1(u);
	}
}

ll query1(int u, int l, int r){
	if(tr1[u].l >= l and tr1[u].r <= r){
		return tr1[u].ma;
	}
	else{
		int mid = tr1[u].l + tr1[u].r >> 1;
		int res = 0;
		if(l <= mid) res = query1(ls(u), l, r);
		if(r > mid) res = jg(res, query1(rs(u), l, r));
		return res;
	}
}
void pushup2(int u){
	tr2[u].ma = jg(tr2[rs(u)].ma, tr2[ls(u)].ma);
}

void build2(int u, int l, int r){
	if(l == r){
		tr2[u] = {l, r, b[l]};
	}
	else{
		tr2[u] = {l, r};
		int mid = l + r >> 1;
		build2(ls(u), l, mid);
		build2(rs(u), mid + 1, r);
		pushup2(u);
	}
}

ll query2(int u, int l, int r){
	if(tr2[u].l >= l and tr2[u].r <= r){
		return tr2[u].ma;
	}
	else{
		int mid = tr2[u].l + tr2[u].r >> 1;
		int res = 0;
		if(l <= mid) res = query2(ls(u), l, r);
		if(r > mid) res = jg(res, query2(rs(u), l, r));
		return res;
	}
}

int main(){
	freopen("match.in", "r", stdin);
	freopen("match.out", "w", stdout);
	int _;
	scanf("%d%d", &_, &n);
	for(int i = 1; i <= n; i ++) scanf("%d", a + i);
	for(int i = 1; i <= n; i ++) scanf("%d", b + i);
	build1(1, 1, n); build2(1, 1, n);
	int q, l, r;
	scanf("%d", &q);
	while(q --){
		res = 0;
		scanf("%d%d", &l, &r);
		for(int i = l; i <= r; i ++){
			for(int j = l; j <= r; j ++){
				ll player1 = query1(1, i, j);
				ll player2 = query2(1, i, j);
				res += player1 * player2;
//				printf("%lld %lld %lld\n", player1, player2, res);
			}
//		printf("%lld\n", query2(1, l, r));
		}
		printf("%lld\n", res);
	}
	return 0;
}
/*
0 2
2 1
1 2
1
1 2
*/