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

const __int128 mod = 1e9 + 7; 
const int N = 3e5 + 7;
int T, n, q, a[N], b[N], t[N << 2][2];
__int128 ans;

int ls(int root) {
	return root << 1;
}
	
int rs(int root) {
	return root << 1 | 1;
}
	
void push_up(int k, int root) {
	t[root][k] = max(t[ls(root)][k], t[rs(root)][k]);
}

void build(int k, int root, int l, int r) {
	if(l == r) {
		if(!k)
			t[root][k] = a[l];
		else
			t[root][k] = b[l];
		return; 
	}
	int mid = (l + r) >> 1;
	build(k, ls(root), l, mid);
	build(k, rs(root), mid + 1, r);
	push_up(k, root);
}	

int query(int k, int root, int l, int r, int ql, int qr) {
	if(l > qr || r < ql)
		return 0;
	if(l >= ql && r <= qr)
		return t[root][k];
	int mid = (l + r) >> 1, maxn = 0;
	if(ql <= mid)
		maxn = max(maxn, query(k, ls(root), l, mid, ql, qr));
	if(qr > mid)
		maxn = max(maxn, query(k, rs(root), mid + 1, r, ql, qr));
	return maxn;
}

int main() {
	freopen("match.in", "r", stdin);
	freopen("match.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> T >> n;
	for(int i = 1; i <= n; ++i)
		cin >> a[i];
	for(int i = 1; i <= n; ++i)
		cin >> b[i];
	build(0, 1, 1, n), build(1, 1, 1, n);
	cin >> q;
	while(q--) {
		int l, r;
		cin >> l >> r;
		ans = 0;
		for(int p = l; p <= r; ++p)
			for(int q = p; q <= r; ++q)
				ans = (ans + 1ll * query(0, 1, 1, n, p, q) * query(1, 1, 1, n, p, q)) % mod;
		cout << (long long)ans << endl;
	}
	return 0;
}