#include<bits/stdc++.h>
#define ll long long
#define int ll
#define For(i,a,b) for(int i=a;i<=b;++i)
const int mod=pow(2,64);
using namespace std;
int qq[100005],w[100005]; 
int l[100005],r[100005];
signed main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	int T,n,ans=0;
	cin>>T>>n;
	For(i,1,n){
		cin>>qq[i];
	}
	For(i,1,n){
		cin>>w[i];
	}
	int q;
	cin>>q;
	For(i,1,q){
		cin>>l[i]>>r[i];
	}
	int maxx1=0,maxx2=0;
	For(i,1,n){
		ans=0;
		For(j,l[i],r[i]){
			maxx1=0,maxx2=0;
			for(int k=j;k<=r[i];++k){
				maxx1=max(maxx1, qq[k]);
				maxx2=max(maxx2, w[k]);				
				ans=(ans+maxx1*maxx2%mod)%mod;
			}
			
		}
		cout<<ans<<endl;
	}
	
}
