#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FILL0(x) memset(x, 0, sizeof(x))
#define FILL1(x) memset(x, -1, sizeof(x))

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int h, w, n, m;
    cin >> h >> w >> n >> m;

    int grid[h][w];
    FILL0(grid);

    rep(i, n)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        grid[a][b] = 1;
    }
    rep(i, m)
    {
        int c, d;
        cin >> c >> d;
        c--;
        d--;
        grid[c][d] = -1;
    }

    int grid2[h][w];
    rep(i, h)
    {
        rep(j, w)
        {
            grid2[i][j]=grid[i][j];
        }
    }

    rep(i, h)
    {
        ll light = 0;
        rep(j, w)
        {
            if (grid2[i][j] == 0)
            {
                grid2[i][j] = light;
            }
            else if (grid2[i][j] == 1)
            {
                light = 1;
            }
            else //-1のとき
            {
                light = 0;
            }
        }
        light = 0;
        for (int j = w - 1; j > -1; j--)
        {
            if (grid2[i][j] == 0)
            {
                grid2[i][j] = light;
            }
            else if (grid2[i][j] == 1)
            {
                light = 1;
            }
            else //-1のとき
            {
                light = 0;
            }
        }
    }



    rep(j, w)
    {
        ll light = 0;
        rep(i, h)
        {
            if (grid[i][j] == 0)
            {
                grid[i][j] = light;
            }
            else if (grid[i][j] == 1)
            {
                light = 1;
            }
            else //-1のとき
            {
                light = 0;
            }
        }
        light = 0;
        for (int i = h - 1; i > -1; i--)
        {
            if (grid[i][j] == 0)
            {
                grid[i][j] = light;
            }
            else if (grid[i][j] == 1)
            {
                light = 1;
            }
            else //-1のとき
            {
                light = 0;
            }
        }
    }

    ll ans = 0;

    rep(i, h)
    {
        rep(j, w)
        {
            if (grid[i][j] == 1 || grid2[i][j]==1)
            {
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cstdint>
#include<cstddef>
#include<vector>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = uint_fast64_t;
template<typename T>
using vec = vector<T>;
#define rep(i, n) for (i64 i = 0; i < (i64)(n); ++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;
void solve(){
}
vec<P> edges[111111];
vec<i64> ans;
i64 n;
void dfs(i64 now){
    for(auto v:edges[now]){
        i64 to = v.first;
        i64 val = v.second;
        if(ans[to] != 0)continue;
        if(val != ans[now]){
            ans[to] = val;
        }else{
            i64 V = val - 1;
            if(V == 0)V = n;
            ans[to] = V;
        }
        dfs(to);
    }
}
int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    i64 m;
    cin >> n >> m;
    ans.resize(n);
    rep(i,m){
        i64 a,b,c;
        cin >> a >> b >> c;
        a--;
        b--;
        edges[a].push_back({b,c});
        edges[b].push_back({a,c});
    }
    ans[0] = 1;
    dfs(0);
    rep(i,n){
        cout << ans[i] << endl;
    }
}