#include <bits/stdc++.h>
using namespace std;

#define il inline
#define ll long long
#define oup(x) wrt(x),ptc(' ')
#define oun(x) wrt(x),ptc('\n')
#define gtc getchar()
#define ptc putchar
#define rd read()
#define rdl readl()
il int read(){int x=0;bool f=0;char c=gtc;while(c<'0'||c>'9'){if(c=='-')f=1;c=gtc;}while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=gtc;}return f?-x:x;}
il ll readl(){ll x=0;bool f=0;char c=gtc;while(c<'0'||c>'9'){if(c=='-')f=1;c=gtc;}while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=gtc;}	return f?-x:x;}
il void wt(unsigned ll x){if(x>10)wt(x/10);ptc(x%10+48);}
il void wrt(ll x){if(x<0)ptc('-'),wt(-x);else wt(x);}

const int N = 250010;
int a[N];
int b[N];

#define FL "match"
int main(){

	freopen(FL".in","r",stdin);
	freopen(FL".out","w",stdout);

	int T = rd, n = rd;
	for(int i = 1; i <= n; i++) a[i] = rd;
	for(int i = 1; i <= n; i++) b[i] = rd;
	
	int q = rd;
	while(q--){
		unsigned ll res = 0;
		int l = rd, r = rd;
		for(int x = l; x <= r; x++){
			for(int y = x; y <= r; y++){
				int mxa = 0, mxb = 0;
				for(int p = x; p <= y; p++){
					if(a[p] > mxa) mxa = a[p];
					if(b[p] > mxb) mxb = b[p];
				}
				res += 1ull * mxa * mxb;
			}
		}
		wt(res),ptc('\n');
	}
	
	

	return 0;
}
/*
0 2
2 1
1 2
1
1 2

*/
