#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
const ll MAXN = 3010;
ll t, n, q;
ull a[MAXN], b[MAXN];
pair<ull, ull> query(ll p, ll q) {
  ull mxa = 0, mxb = 0;
  for (int k = p; k <= q; ++k) {
    mxa = max(mxa, a[k]);
    mxb = max(mxb, b[k]);
  }
  return make_pair(mxa, mxb);
}
int main() {
  freopen("match.in", "r", stdin);
  freopen("match.out", "w", stdout);
  cin >> t >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int j = 1; j <= n; ++j) {
    cin >> b[j];
  }
  ll l, r;
  pair<ull, ull> mx;
  ull ans;
  cin >> q;
  while (q--) {
    cin >> l >> r;
    ans = 0;
    for (int p = l; p <= r; ++p) {
      for (int q = p; q <= r; ++q) {
        mx = query(p, q);
        ans += mx.first * mx.second;
      }
    }
    cout << ans << endl;
  }
  return 0;
}