#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;

struct cmpt {
    unsigned l,r;
};

vector<unsigned> a,b,as,bs;
vector<cmpt> cmpts;

int main() {
    freopen("match.in","r",stdin);
    freopen("match.out","w",stdout);
    cin.tie(NULL);
    ios::sync_with_stdio(false);
    unsigned id,n,Q,li,ri;
    ull sum=0;
    cin>>id>>n;
    a.resize(n);
    b.resize(n);
    for(auto&i:a)
        cin>>i;
    for(auto&i:b)
        cin>>i;
    cin>>Q;
    cmpts.resize(Q);
    for(auto&i:cmpts) {
        cin>>li>>ri;
        i=cmpt{li,ri};
    }
    for(int i=0; i<Q; ++i) {
        as=a;
        bs=b;
        sort(as.begin()+cmpts[i].l,as.begin()+cmpts[i].r);
        sort(bs.begin()+cmpts[i].l,bs.begin()+cmpts[i].r);
        for(int j=cmpts[i].l; j<=cmpts[i].r; ++j) {
            sum+=a[j]*b[j];
        }
        cout<<sum<<'\n';
    }
    return 0;
}

/**
 * 2GiB+4GiB
 * Intel® Core™ i5-6500 CPU @ 3.20GHz × 4 
 * 240.1 GB
 * **/
