#include<bits/stdc++.h>
using namespace std;
const int N = 3e5+10;
long long int ans;
int n,a[N],b[N],max1,max2,l,r,Q;
const long long int mod = 1e16;
int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	ios::sync_with_stdio(0);
	int T;
	cin >> T >> n;
	for (int i=1;i<=n;i++) cin >> a[i];
	for (int j=1;j<=n;j++) cin >> b[j];
	cin >> Q;
//	cout <<1 << endl;
//cout << Q << endl;
	while (Q--)
	{
		ans=0;
		cin >> l >> r;
//		cout << 1 << endl;
		for (int i=l;i<=r;i++)
		for (int j=i;j<=r;j++)
		{
//			cout << 1 << endl;
			max1=max2=0;
			for (int k=i;k<=j;k++) 
			max1=max(max1,a[k]),max2=max(max2,b[k]);
			ans=(ans+max1*max2%mod)%mod;
		}
		cout << ans << endl;
	}
	return 0;
}