#include<bits/stdc++.h>
#define rint register int
#define fu(i,a,b,d,c) for(rint i=a;i<=b&&c;i+=d)
#define fd(i,a,b,d,c) for(rint i=a;i>=b&&c;i-=d)
using namespace std;
inline int read(){
	char c=0,f=1;int num=0;
	while(c<'0'||c>'9')((c=getchar())=='-')&&(f=-f);
	while(c>='0'&&c<='9')num=(num<<1)+(num<<3)+(c^48),c=getchar();
	return num*f;
}
const int MAXN = 250050;
unsigned long long ans=0;
int n,a[MAXN],b[MAXN],Q,l[MAXN],r[MAXN];
signed main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	read(),n=read();
	fu(i,1,n,1,1)a[i]=read();
	fu(i,1,n,1,1)b[i]=read();
	Q=read();
	fu(i,1,Q,1,1)l[i]=read(),r[i]=read();
	fu(i,1,Q,1,1){
		ans=0;
		fu(p,l[i],r[i],1,1){
		int mx1=0,mx2=0;
			fu(q,p,r[i],1,1){
				mx1=max(mx1,a[q]),mx2=max(mx2,b[q]);
				ans+=1ull*mx1*mx2;
			}
		}
		printf("%llu\n",ans);
	}
}
