#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll t,n,a[250050],b[250050],Q;
ll maxa[3030][3030],maxb[3030][3030];
ll ans;
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	scanf("%lld %lld",&t,&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	for(int i=1;i<=n;i++){
		scanf("%lld",&b[i]);
	}
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j++){
			maxa[i][j]=max(maxa[i][j-1],a[j]);
			maxb[i][j]=max(maxb[i][j-1],b[j]);
		}
	}
	scanf("%lld",&Q);
	while(Q--){
		ll l,r;
		ans=0;
		scanf("%lld %lld",&l,&r);
		for(int p=l;p<=r;p++){
			for(int q=p;q<=r;q++){
				ans=(ans+maxa[p][q]*maxb[p][q])%mod;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}
/*
1 0
4 3 1 1
001
010
000
000

*/