#include<bits/stdc++.h>
#define ll long long
#define inf (1<<30)
#define INF (1ll<<60)
#define pii pair<int,int>
#define mkp make_pair
#define fi first
#define se second
#define pb emplace_back
#define siz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define pt(a) cerr<<#a<<'='<<a<<' '
#define pts(a) cerr<<#a<<'='<<a<<'\n'
#define ull unsigned long long
using namespace std;
const int MAXN=5e5+10;
int n,a[MAXN],b[MAXN];
signed main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int T;cin>>T>>n;
	rep(i,1,n) cin>>a[i];
	rep(i,1,n) cin>>b[i];
	int Q;cin>>Q;
	while(Q--){
		int l,r;cin>>l>>r;
		ull ans=0;
		rep(i,l,r){
			int mxa=0,mxb=0;
			rep(j,i,r){
				mxa=max(mxa,a[j]);
				mxb=max(mxb,b[j]);
				ans+=1ull*mxa*mxb;
			}
		}cout<<ans<<'\n';
	}
	return 0;
}