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

namespace IO {
inline int read() {
    int x = 0, f = 0;
    char ch = getchar();
    while (!isdigit(ch)) f |= ch == '-', ch = getchar();
    while (isdigit(ch)) x = 10 * x + ch - '0', ch = getchar();
    return f ? -x : x;
}
template<typename T>
inline void write(T x) {
    static int stk[65], top;
    top = 0;
    if (x < 0) putchar('-'), x = -x;
    do {
        stk[++top] = x % 10;
        x /= 10;
    } while (x);
    while (top) {
        putchar(stk[top] + '0');
        top--;
    }
}
template<typename T>
inline void write(T x, char ch) {
    write(x), putchar(ch);
}
}

using pii = pair<int, int>;
using u64 = unsigned long long;

const int N = 250005;

u64 ans[N], cur[N];
vector<pii> ask[N];
int a[N], b[N];
int stka[N], topa;
int stkb[N], topb;
int n, m, q;

int main() {
    freopen("match.in", "r", stdin);
    freopen("match.out", "w", stdout);
    IO::read(), n = IO::read();
    for (int i = 1; i <= n; i++) a[i] = IO::read();
    for (int i = 1; i <= n; i++) b[i] = IO::read();
    a[0] = b[0] = n + 1;
    q = IO::read();
    for (int i = 1; i <= q; i++) {
        int l = IO::read(), r = IO::read();
        ask[r].push_back({l, i});
    }
    for (int i = 1; i <= n; i++) {
        int t1 = 0, t2 = 0;
        // static int pre[N];
        for (int j = i; j >= 1; j--) {
            t1 = max(t1, a[j]);
            t2 = max(t2, b[j]);
            // pre[j]=t1*t2;
            cur[j] += 1ull * t1 * t2;
        }
        static u64 suf[N];
        suf[i + 1] = 0;
        for (int j = i; j >= 1; j--)
            suf[j] = suf[j + 1] + cur[j];
        // for(int j=1;j<=i;j++)
        //     printf("%d ",pre[j]);
        // puts("");
        // if (i<=10);
        // else continue;
        // for(int j=1;j<=i;j++)
        //     printf("%llu ",cur[j]);
        // puts("");
        for (int j = 0; j < ask[i].size(); j++) {
            int l = ask[i][j].first, id = ask[i][j].second;
            ans[id] = suf[l];
        }
    }
    for (int i = 1; i <= q; i++) IO::write(ans[i], '\n');
    return 0;
}