#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
static const ll N = 2e5+5e4;
static const ll P = 1.84467e+19;

ll t, n, q, l, r, ans, a[N], b[N]; 

inline ll read() {
	register ll s = 0ll;
	register bool m = false;
	register char ch = getchar();
	while(! isdigit(ch)) {
		if(ch == '-')
			m = true;
		ch = getchar();
	}
	while(isdigit(ch)) s = (s << 1ll) + (s << 3ll) + (ch ^ 48ll), ch = getchar();
	return m ? -s : s;
}

namespace _SUB {
	inline void _SOL(void) {
		l = read(), r = read();
		ans = 0;
		for(register ll p = l;p <= r; ++p) {
			for(register ll q = p;q <= r; ++q) {
				register ll m1 = 0, m2 = 0;
				for(register ll i = p;i <= q; ++i) {
					m1 = max(m1, a[i]), m2 = max(m2, b[i]);
				}
//				cout << "m1=" << m1 << " m2=" << m2 << endl;
				ans = (ans+m1*m2%P)%P;
			}
		}
		printf("%lld\n", ans%P);
	}
}

signed main(int argc, char const* argv[]) {
	freopen("match.in", "r", stdin);
	freopen("match.out", "w", stdout);
	t = read(), n = read();
	for(register ll i = 1;i <= n; ++i) a[i] = read();
	for(register ll i = 1;i <= n; ++i) b[i] = read();
	q = read();
	while(q --) _SUB::_SOL();
	return 0;
}
#if false


#endif
