#include<bits/stdc++.h>
using namespace std;
#define fr(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define IO ios::sync_with_stdio(0)
#define ll long long
#define ull unsigned long long
inline void rd(int &x) {
	x=0;
	bool f=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') {
		if(ch=='-')f=1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		x=x*10+ch-'0';
		ch=getchar();
	}
	if(f)x=-x;
}
const int N=2.5e5+10;
int T,n,m1,m2;
int lg[N],p[30],a[N],b[N],q,l,r;
ull ans;

inline void pre() {
	p[0]=1;
	for(int i=1,j=0; i<=n; ++i) {
		lg[i]=j;
		if(i==p[j])++j,p[j]=(p[j-1]<<1);
	}
	return;
}
int main() {
	fr("match");
	IO;
	rd(T),rd(n);
//	pre();
	for(int i=1; i<=n; ++i)
		rd(a[i]);
	for(int i=1; i<=n; ++i)
		rd(b[i]);
	rd(q);
//	cout<<q<<endl;
	while(q--) {
		ans=0ull;
		rd(l),rd(r);
		for(int i=l; i<=r; ++i) {
			m1=a[i],m2=b[i];
			for(int j=i; j<=r; ++j) {
				m1=max(a[j],m1);
				m2=max(b[j],m2);
				ans+=1ull*m1*m2;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}