#if defined(_USE_PCH_)
#include "pch.hpp"
#else
#include <bits/stdc++.h>
#endif
#define RNG(V_, A_, B_, ...) for(int V_=(A_), V_##_END=(B_) __VA_OPT__(,) __VA_ARGS__; V_<=V_##_END; V_++)
#define IRNG(V_, A_, B_) for(int V_=(A_), V_##_END=(B_); V_>=V_##_END; V_--)
#ifdef _WIN32
#define long int64_t
#endif
#define _UN using namespace
using namespace std;
const int MAXN=1e6+10,MAXQ=5e6+10;
int n,qn; __int128 ans[MAXQ];
struct{ int a,b,c; } A[MAXN],S[MAXN];
struct{ __int128 sum,add; int ti; } F[MAXN];
struct{ int l,r,id; } Q[MAXQ];
ostream& operator<<(ostream& os,__int128 x){
    if(!x){ os<<'0'; return os; }
    if(x>9) os<<(x/10);
    return os<<char(x % 10 + '0');
}
int main(){
#if defined(_LOCAL_)
    freopen("in","r",stdin);
    freopen("out","w",stdout);
//  freopen("/dev/null","w",stderr);
#else
//  freopen("centroid.in","r",stdin);
//  freopen("centroid.out","w",stdout);
#endif
    ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
    cin>>n>>qn;
    RNG(i,1,n) cin>>A[i].a;
    RNG(i,1,n) cin>>A[i].b;
    RNG(i,1,n) cin>>A[i].c;
    RNG(i,1,qn) cin>>Q[i].l>>Q[i].r,Q[i].id=i;
    sort(Q+1,Q+qn+1,[](auto x,auto y){ return x.r<y.r; });
    RNG(r,1,n,qi=1){
        auto calc=[](int i,int t){ return F[i].sum+F[i].add*(t-F[i].ti); };
        S[r]=A[r],F[r]=F[r-1];
        int l=r-1;
        for(; l; l--){
            auto a1=S[l].a&A[r].a,b1=S[l].b|A[r].b,c1=__gcd(S[l].c,A[r].c);
            if(a1==S[l].a&&b1==S[l].b&&c1==S[l].c) break;
            S[l]={a1,b1,c1};
        }
        auto x=F[l].add;
        RNG(i,l+1,r){
            x+=1l*S[i].a*S[i].b*S[i].c;
            F[i].sum=calc(i,r-1)+x,F[i].add=x,F[i].ti=r;
        }
        for(; qi<=qn&&Q[qi].r==r; qi++) ans[Q[qi].id]=calc(r,r)-calc(Q[qi].l-1,r);
    }
    RNG(qi,1,qn) cout<<ans[qi]<<"\n";
}