#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=2021;

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int h, w, q1, q2;
    cin >> h >> w >> q1 >> q2;

    vector<int> row_all, col_all;
    struct Qadd{int r1,r2,c1,c2,x;};
    struct QQry{int r1,r2,c1,c2;};
    vector<Qadd> adds; vector<QQry> qrys;

    for(int i=0;i<q1;i++){
        int r1,r2,c1,c2,x;cin>>r1>>r2>>c1>>c2>>x;
        adds.push_back({r1,r2,c1,c2,x});
        row_all.push_back(r1); row_all.push_back(r2+1);
        col_all.push_back(c1); col_all.push_back(c2+1);
    }
    for(int i=0;i<q2;i++){
        int r1,r2,c1,c2;cin>>r1>>r2>>c1>>c2;
        qrys.push_back({r1,r2,c1,c2});
        row_all.push_back(r1); row_all.push_back(r2+1);
        col_all.push_back(c1); col_all.push_back(c2+1);
    }
    
    sort(row_all.begin(),row_all.end());row_all.erase(unique(row_all.begin(),row_all.end()),row_all.end());
    sort(col_all.begin(),col_all.end());col_all.erase(unique(col_all.begin(),col_all.end()),col_all.end());
    map<int,int> row2id, col2id;
    for(int i=0;i<row_all.size();i++) row2id[row_all[i]] = i;
    for(int i=0;i<col_all.size();i++) col2id[col_all[i]] = i;
    
    vector<ll> col_len(col_all.size());
    for(int i=0;i+1<col_all.size();i++) col_len[i]=col_all[i+1]-col_all[i];
    col_len[col_all.size()-1]=1;
    
    vector<ll> row_len(row_all.size());
    for(int i=0;i+1<row_all.size();i++) row_len[i]=row_all[i+1]-row_all[i];
    row_len[row_all.size()-1]=1;

    int nrow = row_all.size(), ncol= col_all.size();
    
    vector<map<int,ll>> diff(nrow);

    
    for(auto& op:adds){
        int r1=row2id[op.r1], r2=row2id[op.r2+1]-1;
        int c1=col2id[op.c1],c2=col2id[op.c2+1]-1;
        for(int r=r1;r<=r2;r++){
            diff[r][c1] = (diff[r][c1]+op.x)%MOD;
            diff[r][c2+1] = (diff[r][c2+1]-op.x+MOD)%MOD;
        }
    }

    
    for(auto& qry: qrys){
        int rr1=row2id[qry.r1], rr2=row2id[qry.r2+1]-1;
        int cc1=col2id[qry.c1], cc2=col2id[qry.c2+1]-1;
        ll sum=0;
        for(int r=rr1; r<=rr2; r++){
            
            ll val=0;
            auto& mp=diff[r];
            
            vector<int> keys;
            for(auto [k,_]:mp){
                if(k > cc2) break;
                keys.push_back(k);
            }
            if(keys.empty() || keys[0]>cc2) continue; 
            ll cur=0;
            int last = cc1;
            for(int i=0;i<keys.size();i++){
                int pos = max(keys[i], cc1);
                if(i==0 && keys[0]>cc1) pos=cc1;
                if(keys[i]>cc2) break;
                if(i>0)last=keys[i-1];
                
                if(keys[i]>=cc1){
                    ll len = min(col_all[cc2+1], col_all[keys[i]+1]) - max(col_all[cc1], col_all[keys[i]]);
                    
                }
            }
            
            
            vector<ll> raw(ncol+2,0);
            for(auto[x, v]: mp){
                raw[x] = (raw[x]+v)%MOD;
            }
            
            for(int i=1;i<=ncol;i++)
                raw[i] = (raw[i]+raw[i-1])%MOD;
            
            for(int j=cc1;j<=cc2;j++){
                sum = (sum + raw[j]*col_len[j]%MOD*row_len[r]%MOD)%MOD;
            }
        }
        cout<<sum<<'\n';
    }
}