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

template<typename T>
inline void read(T &x) {
    x = 0; char ch = getchar();
    bool f = 0;
    while (!isdigit(ch)) f |= ch == '-', ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
    if (f) x = -x;
}
template<typename T>
inline void write(T x, char c) {
    if (x == 0) {
        putchar('0'), putchar(c);
        return;
    }
    static int stk[30];
    int top = 0;
    while (x) stk[++top] = x % 10, x /= 10;
    while (top) putchar('0' + stk[top--]);
    putchar(c);
}

using u64 = unsigned long long;

const int N = 250005;
int T, n, a[N], b[N], q, s1[N], t1, s2[N], t2, ql[N], qr[N];
vector<pair<int, int>> qry[N];
u64 ans[N];

struct node {
    u64 ta, tb;
    node(u64 ta = 0, u64 tb = 0) : ta(ta), tb(tb) {}
    inline node operator+(const node &rhs) const {
        return node(ta + rhs.ta, tb + rhs.tb);
    }
    inline void operator+=(const node &rhs) {
        *this = *this + rhs;
    }
};

struct node_t {
    u64 len, a, b, ab;
    node lazy;
    inline void apply(const node &x) {
        ab += x.ta * b + x.tb * a + len * x.ta * x.tb;
        a += len * x.ta;
        b += len * x.tb;
        lazy += x;
    }
} t[N << 2];

inline void push_up(int p) {
    t[p].a = t[p << 1].a + t[p << 1 | 1].a;
    t[p].b = t[p << 1].b + t[p << 1 | 1].b;
    t[p].ab = t[p << 1].ab + t[p << 1 | 1].ab;
}

inline void push_down(int p) {
    if (t[p].lazy.ta || t[p].lazy.tb) {
        t[p << 1].apply(t[p].lazy);
        t[p << 1 | 1].apply(t[p].lazy);
        t[p].lazy = node();
    }
} 

void build(int p, int l, int r) {
    t[p].len = r - l + 1;
    if (l == r) return;
    int mid = (l + r) >> 1;
    build(p << 1, l, mid);
    build(p << 1 | 1, mid + 1, r);
}

void modify(int p, int l, int r, int ll, int rr, const node &x) {
    if (l >= ll && r <= rr) {
        t[p].apply(x);
        return;
    }
    push_down(p);
    int mid = (l + r) >> 1;
    if (mid >= ll) modify(p << 1, l, mid, ll, rr, x);
    if (mid < rr) modify(p << 1 | 1, mid + 1, r, ll, rr, x);
    push_up(p);
}

u64 query(int p, int l, int r, int ll, int rr) {
    if (l >= ll && r <= rr) return t[p].ab;
    push_down(p);
    int mid = (l + r) >> 1;
    u64 res = 0;
    if (mid >= ll) res += query(p << 1, l, mid, ll, rr);
    if (mid < rr) res += query(p << 1 | 1, mid + 1, r, ll, rr);
    return res;
}

int main() {
    freopen("match3.in", "r", stdin);
    freopen("match.out", "w", stdout);

    read(T), read(n);
    for (int i = 1; i <= n; ++i) read(a[i]);
    for (int i = 1; i <= n; ++i) read(b[i]);
    read(q);
    for (int i = 1; i <= q; ++i) {
        read(ql[i]), read(qr[i]);
        qry[qr[i]].emplace_back(ql[i], i);
    }

    build(1, 1, n);
    for (int i = 1; i <= n; ++i) {
        while (t1 && a[s1[t1]] < a[i]) {
            int l = s1[t1 - 1] + 1, r = s1[t1];
            modify(1, 1, n, l, r, node(a[i] - a[s1[t1]], 0));
            --t1;
        }
        while (t2 && b[s2[t2]] < b[i]) {
            int l = s2[t2 - 1] + 1, r = s2[t2];
            modify(1, 1, n, l, r, node(0, b[i] - b[s2[t2]]));
            --t2;
        }
        s1[++t1] = i, s2[++t2] = i;
        modify(1, 1, n, i, i, node(a[i], b[i]));
        for (int o = 1; o <= q; ++o) {
            if (qr[o] >= i) ans[o] += query(1, 1, n, ql[o], qr[o]);
        }
    }

    for (int i = 1; i <= q; ++i) write(ans[i], '\n');

    return 0;
}