#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::cerr;

constexpr int N = 3e5 + 5;
#define int long long

int n;
int a[N], b[N];
class SegmentTree {
  public:
    int t[N << 2];
    void build(int l, int r, int k, int x[]) {
        if (l == r) {
            t[k] = x[l];
            return;
        }
        int mid = (l + r) / 2;
        build(l, mid, k * 2, x), build(mid + 1, r, k * 2 + 1, x);
        t[k] = std::max(t[k * 2], t[k * 2 + 1]);
    }
    int query(int L, int R, int l, int r, int k) {
        if (L <= l && r <= R) return t[k];
        int mid = (l + r) / 2;
        int ret = 0;
        if (L <= mid) ret = std::max(ret, query(L, R, l, mid, k * 2));
        if (mid < R) ret = std::max(ret, query(L, R, mid + 1, r, k * 2 + 1));
        return ret;
    }
} t1, t2;

signed main() {
    freopen("match.in", "r", stdin), freopen("match.out", "w", stdout);
    std::ios::sync_with_stdio(false), cin.tie(nullptr);

    int T;
    cin >> T >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) cin >> b[i];
    t1.build(1, n, 1, a), t2.build(1, n, 1, b);
    int Q;
    cin >> Q;
    while (Q--) {
        int l, r;
        unsigned long long ans = 0;
        cin >> l >> r;
        for (int p = l; p <= r; ++p)
            for (int q = p; q <= r; ++q)
                ans += 1ull * t1.query(p, q, 1, n, 1) * t2.query(p, q, 1, n, 1);
        cout << ans << '\n';
    }

    return 0;
}
