/**
 * @file match.cpp
 * @author Macesuted Moe (i@macesuted.moe)
 * @date 2022-11-26
 * 
 * @copyright Copyright (c) 2022
 */

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

bool mem1;

#ifndef LOCAL
#define endl '\n'
#endif

#define maxn 250005
#define maxlgn 20

typedef pair<int, int> pii;

int a[maxn], b[maxn], al[maxn], ar[maxn], bl[maxn], br[maxn], lg[maxn], rootA, rootB, n;
pii ast[maxn][maxlgn], bst[maxn][maxlgn];
stack<int> S;
uint64_t va[maxn], vb[maxn];

int findMaxPosA(int l, int r) {
    int v = lg[r - l + 1];
    return max(ast[l][v], ast[r - (1 << v) + 1][v]).second;
}
int findMaxPosB(int l, int r) {
    int v = lg[r - l + 1];
    return max(bst[l][v], bst[r - (1 << v) + 1][v]).second;
}
void buildB(int l, int r, int p) {
    if (l < p) buildB(l, p - 1, bl[p] = findMaxPosB(l, p - 1));
    if (p < r) buildB(p + 1, r, br[p] = findMaxPosB(p + 1, r));
    vb[p] = vb[bl[p]] + vb[br[p]] + (uint64_t)b[p] * (p - l + 1) * (r - p + 1);
    return;
}
uint64_t queryB(int l, int r, int p, int ql, int qr) {
    if (ql <= l && r <= qr) return vb[p];
    uint64_t ans = 0;
    if (ql < p) ans += queryB(l, p - 1, bl[p], ql, qr);
    if (p < qr) ans += queryB(p + 1, r, br[p], ql, qr);
    if (ql <= p && p <= qr)
        ans += (uint64_t)b[p] * (p - max(l, ql) + 1) * (min(r, qr) - p + 1);
    return ans;
}
uint64_t queryB(int l, int r) { return queryB(1, n, rootB, l, r); }
uint64_t queryB(int l, int m, int r) {
    return queryB(l, r) - queryB(l, m - 1) - queryB(m + 1, r);
}
void buildA(int l, int r, int p) {
    if (l < p) buildA(l, p - 1, al[p] = findMaxPosA(l, p - 1));
    if (p < r) buildA(p + 1, r, ar[p] = findMaxPosA(p + 1, r));
    va[p] = va[al[p]] + va[ar[p]] + (uint64_t)a[p] * queryB(l, p, r);
    return;
}
uint64_t queryA(int l, int r, int p, int ql, int qr) {
    if (ql <= l && r <= qr) return va[p];
    uint64_t ans = 0;
    if (ql < p) ans += queryA(l, p - 1, al[p], ql, qr);
    if (p < qr) ans += queryA(p + 1, r, ar[p], ql, qr);
    if (ql <= p && p <= qr) ans += (uint64_t)a[p] * queryB(max(l, ql), p, min(r, qr));
    return ans;
}
void solve(void) {
    int id, q;
    cin >> id >> n;
    for (int i = 1; i <= n; i++) cin >> a[i], ast[i][0] = {a[i], i};
    for (int i = 1; i <= n; i++) cin >> b[i], bst[i][0] = {b[i], i};
    for (int i = 1; i < maxlgn; i++)
        for (int j = 1; j + (1 << i) - 1 <= n; j++)
            ast[j][i] = max(ast[j][i - 1], ast[j + (1 << (i - 1))][i - 1]),
                bst[j][i] = max(bst[j][i - 1], bst[j + (1 << (i - 1))][i - 1]);
    rootB = findMaxPosB(1, n);
    buildB(1, n, rootB);
    rootA = findMaxPosA(1, n);
    buildA(1, n, rootA);
    cin >> q;
    while (q--) {
        int l, r;
        cin >> l >> r;
        cout << queryA(1, n, rootA, l, r) << endl;
    }
    return;
}

bool mem2;

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#ifndef LOCAL
    freopen("match.in", "r", stdin), freopen("match.out", "w", stdout);
#endif
#ifdef LOCAL
    cerr << "MEMORY: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
#endif

    for (int i = 2; i < maxn; i++) lg[i] = lg[i >> 1] + 1;

    int _ = 1;
    while (_--) solve();

#ifdef LOCAL
    cerr << "TIME: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
#endif
    return 0;
}
