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

//#define int long long

template<class T>
inline bool read(T &x){
	x=0;char ch;bool f=0;
	for(ch=getchar();!isdigit(ch);ch=getchar()){
		if(ch==EOF)return 0;
		if(ch=='-')f=1;
	}
	for (;isdigit(ch);ch=getchar()){
		x=(x<<1)+(x<<3)+(ch^48);
	}
	if(f)x=-x;
	return 1;
} 

template<class T>
void write(T x){
	if(x<0){
		putchar('-');
		write(-x);
		return ;
	}
	if(x>9)write(x/10);
	putchar(x%10|48);
}

template<class T>
inline void writeln(T x){
	write(x);putchar('\n');
}

template<class T>
inline void writespace(T x){
	write(x);putchar(' ');
}

int T,n;
unsigned long long a[250010],b[250010];
int Q;

signed main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	read(T);read(n);
	for(register int i=1;i<=n;++i)read(a[i]);
	for(register int j=1;j<=n;++j)read(b[j]);
	//for(register int )
	read(Q);
	while(Q--){
		int l,r;
		read(l);read(r);
		unsigned long long ans=0;
		for(register int p=l;p<=r;++p){
			unsigned long long maxa=0,maxb=0;
			for(register int q=p;q<=r;++q){
				maxa=max(maxa,a[q]),maxb=max(maxb,b[q]);
				//cout<<p<<" "<<q<<" "<<maxa<<" "<<maxb<<endl;
				ans+=maxa*maxb;
				
				//ans=add(ans,mul(maxa,maxb));
			}
		}
		writeln(ans);
	}
	return 0;
}