#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<set>
#include<map>
#include<string>
#include<cstring>
using namespace std;
typedef unsigned long long ll;
const int INF=0x3f3f3f3f;
const int N=3e5+10;
int a[N],b[N];
int n;
int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	int T;
	scanf("%d%d",&T,&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&b[i]);
	}
	int q;
	scanf("%d",&q);
	for(int k=1;k<=q;k++)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		ll ans=0;
		for(int i=l;i<=r;i++)
		{
			for(int j=i;j<=r;j++)
			{
				int maxa=0,maxb=0;
				for(int h=i;h<=j;h++)
				{
					maxa=max(maxa,a[h]);
					maxb=max(maxb,b[h]);
				}
				ans+=(ll)maxa*maxb;
			}
		}
		printf("%llu\n",ans);
	}
	return 0;
}