#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
int main() {
int N, K;
cin >> N;
vector<int> A(N), B(N);
vector<int> X(K), Y(K);
for (int i = 0; i < N; ++i) cin >> A[i];
for (int i = 0; i < N; ++i) cin >> B[i];
cin>>K;
for (int i = 0; i < K; ++i){
cin >> X[i] >> Y[i];
X[i]--;
Y[i]--;
}
// Sort A and B
sort(A.begin(), A.end());
sort(B.begin(), B.end());
// Compute prefix sums
vector<ll> prefixA(N + 1, 0), prefixB(N + 1, 0);
for (int i = 1; i <= N; ++i) {
prefixA[i] = prefixA[i - 1] + A[i - 1];
prefixB[i] = prefixB[i - 1] + B[i - 1];
}
// Answer each query
for (int k = 0; k < K; ++k) {
int x = X[k], y = Y[k];
ll sumA = prefixA[x];
ll sumB = prefixB[y];
// Total sum of absolute differences
ll result = x * sumB + y * sumA - 2 * (prefixA[x] * y);
cout << result << endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdXNpbmcgbGwgPSBsb25nIGxvbmc7CgppbnQgbWFpbigpIHsKICAgIGludCBOLCBLOwogICAgY2luID4+IE47CiAgICB2ZWN0b3I8aW50PiBBKE4pLCBCKE4pOwogICAgdmVjdG9yPGludD4gWChLKSwgWShLKTsKICAgIAogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBOOyArK2kpIGNpbiA+PiBBW2ldOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBOOyArK2kpIGNpbiA+PiBCW2ldOwogICAgCiAgICBjaW4+Pks7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IEs7ICsraSl7CiAgICAJY2luID4+IFhbaV0gPj4gWVtpXTsKICAgIAlYW2ldLS07CiAgICAJWVtpXS0tOwogICAgfSAKICAgIAogICAgLy8gU29ydCBBIGFuZCBCCiAgICBzb3J0KEEuYmVnaW4oKSwgQS5lbmQoKSk7CiAgICBzb3J0KEIuYmVnaW4oKSwgQi5lbmQoKSk7CiAgICAKICAgIC8vIENvbXB1dGUgcHJlZml4IHN1bXMKICAgIHZlY3RvcjxsbD4gcHJlZml4QShOICsgMSwgMCksIHByZWZpeEIoTiArIDEsIDApOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gTjsgKytpKSB7CiAgICAgICAgcHJlZml4QVtpXSA9IHByZWZpeEFbaSAtIDFdICsgQVtpIC0gMV07CiAgICAgICAgcHJlZml4QltpXSA9IHByZWZpeEJbaSAtIDFdICsgQltpIC0gMV07CiAgICB9CiAgICAKICAgIC8vIEFuc3dlciBlYWNoIHF1ZXJ5CiAgICBmb3IgKGludCBrID0gMDsgayA8IEs7ICsraykgewogICAgICAgIGludCB4ID0gWFtrXSwgeSA9IFlba107CiAgICAgICAgCiAgICAgICAgbGwgc3VtQSA9IHByZWZpeEFbeF07CiAgICAgICAgbGwgc3VtQiA9IHByZWZpeEJbeV07CiAgICAgICAgCiAgICAgICAgLy8gVG90YWwgc3VtIG9mIGFic29sdXRlIGRpZmZlcmVuY2VzCiAgICAgICAgbGwgcmVzdWx0ID0geCAqIHN1bUIgKyB5ICogc3VtQSAtIDIgKiAocHJlZml4QVt4XSAqIHkpOwogICAgICAgIGNvdXQgPDwgcmVzdWx0IDw8IGVuZGw7CiAgICB9CiAgICAKICAgIHJldHVybiAwOwp9Cg==