
#include<bits/stdc++.h>
using namespace std;
#define int unsigned long long
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fr(i,a,b) for(int i=a;i>=b;i--)
#define wt(x) write(x),puts("")
inline int read(){
	int x=0,k=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') k=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+ch-'0';
		ch=getchar();
	}
	return x*k;
}
void write(int x){
	if(x>9){
		write(x/10);
	}
	putchar(x%10+'0');
	return ;
}
const int N=2e6+7,mod=998244353;
int n,m,tot,cnt,ans,k;
int a[N],b[N],sum[3001][3001],sum1[3001][3001];
signed main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	int nm=read();
	n=read();
	fo(i,1,n) a[i]=read();
	fo(i,1,n) b[i]=read();
	fo(i,1,n){
		int x=0,y=0;
		fo(j,i,n){
			x=max(x,a[j]);
			y=max(y,b[j]);
			sum[i][j]=x*y;

		}
	}
	fo(i,1,n){
		fo(j,i,n){
			sum1[i][j]=sum1[i][j-1]+sum[i][j];
		}
	}
	m=read();
	fo(i,1,m){
		int l=read(),r=read();
		int num=0;
		fo(j,l,r){
			num+=sum1[j][r];
		}
		wt(num);
	}
}
