#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,T,q;
int a[250010];
int b[250010];
signed main(){
	ios::sync_with_stdio(false);
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	cin>>T>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		cin>>b[i];
	}
	cin>>q;
	int ans=0;
	for(int cnt=1;cnt<=q;cnt++){
		int l,r;
		cin>>l>>r;
		cout<<l<<r;
		for(int i=l;i<=r;i++){
			for(int j=i;j<=r;j++){
				int maxa=-1;
				for(int k=i;k<=j;k++){
					maxa=max(maxa,a[k]);
				}
				int maxb=-1;
				for(int k=i;k<=j;k++){
					maxb=max(maxb,b[k]);
				}
				ans=ans+maxa*maxb;
			}
	}	
	}
	cout<<ans<<endl;
	return 0;
}/*
0 2
2 1
1 2
1
1 2
*/