#include<algorithm>
#include<queue>
#include<set>
#include<vector>
#include<cstring>
#include<cmath>
#include<stdio.h>
#include<iostream>
#define ll long long
#define inf 0x3f3f3f3f
#define I inline
#define rr register 
#define RI rr int
#define C const
#define CI const int&
#define maxn 100005
#define int unsigned long long
#define mod 18446744073709551616
using std::set;
using std::vector;
using std::queue;
using std::priority_queue;
using std::max;
using std::cout;
template<typename T>I void read(T &x){RI f=1;x=0;rr char c=getchar();while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0',c=getchar();}x*=f;}
int n,a[maxn];
class tree1{
	private:
		int val[maxn<<1];
		inline void in_scan()
		{
			for(register int i=1;i<=n;i++)
				read(a[i]);
		}
		inline void in_build(CI root,CI l,CI r)
		{
			if(l==r) return (void)(val[root]=a[l]);
			register int mid=l+r>>1;
			in_build(root<<1,l,mid);in_build(root<<1|1,mid+1,r);
			val[root]=max(val[root<<1],val[root<<1|1]);
		}
		inline int in_query(CI root,CI l,CI r,CI u,CI v)
		{
			if(u<=l&&r<=v) return val[root];
			register int mid=l+r>>1;
			if(v<=mid) return in_query(root<<1,l,mid,u,v);
			if(u>mid) return in_query(root<<1|1,mid+1,r,u,v);
			return max(in_query(root<<1,l,mid,u,mid),in_query(root<<1|1,mid+1,r,mid+1,v));
		}
	public:
		inline void build(){in_build(1,1,n);}
		inline void scan(){in_scan();}
		inline int query(CI l,CI r){return in_query(1,1,n,l,r);}
}A,B;
int ans;
signed main(void)
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	register int T;read(T),read(n);
	A.scan(),A.build();B.scan(),B.build();
	register int m;read(m);
	for(register int i=1;i<=m;i++)
	{
		register int l,r;read(l),read(r);
		for(register int i=l;i<=r;i++)
			for(register int j=i;j<=r;j++)
				ans+=A.query(i,j)*B.query(i,j);
		cout<<ans<<"\n";ans=0;
	}
	//need gaojing
	return 0;
}