#include<bits/stdc++.h>

using namespace std;

const int N=2e5+5;
const int mod=1e9+7;

int ans[N],parent[N];
vector<pair<int,int>>adj[N];
pair<pair<int,int>,int>edges[N];

int FindParent(int x)
{
    if(parent[x] == x)return x;
    return parent[x]=FindParent(parent[x]);
}

void DFS(int cur,int par)
{
    int x,y;
    for(auto it : adj[cur])
    {
        x=it.first;
        y=it.second;
        if(!(x ^ par))continue;
        if(ans[cur] == y)
        {
            if(y == 1)ans[x]=2;
            else ans[x]=1;
        }
        else ans[x]=y;
        DFS(x,cur);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int i,m,n,x,y,z,px,py;
    cin >> n >> m;
    for(i=1;i<=m;i++)
    {
        cin >> x >> y >> z;
        edges[i].first.first=x;
        edges[i].first.second=y;
        edges[i].second=z;
    }
    for(i=1;i<=n;i++)parent[i]=i;
    for(i=1;i<=m;i++)
    {
        x=edges[i].first.first;
        y=edges[i].first.second;
        z=edges[i].second;
        px=FindParent(x);
        py=FindParent(y);
        if(px != py)
        {
            parent[py]=px;
            adj[x].emplace_back(y,z);
            adj[y].emplace_back(x,z);
        }
    }
    ans[1]=1;
    DFS(1,1);
    for(i=1;i<=n;i++)cout << ans[i] << '\n';
    return 0;
}

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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second

mapii row,col;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int r,c,i,j,k,l,m,n,h,w;

    cin >> h >> w >> n >> m;

    char s[h+2][w+2];
    for(i=1; i<=h; i++)
    {
        for(j=1; j<=w; j++)
        {
            s[i][j] = '*';
        }
    }

    int a,b;
    vector<pair<int,int>>pt;
    for(i=0; i<n; i++)
    {
        cin >> a >> b;

        pt.pb({a,b});
    }
    for(i=0; i<m; i++)
    {
        cin >> a >> b;

        s[a][b] = '#';
    }
    int no = 0;

    for(auto x : pt)
    {
        a = x.F;
        b = x.S;
        i = a,j = b;
        while(i)
        {
            if(s[i][j] == '#')break;
            s[i][j] = '1';
            i--;
        }
        i = a,j = b;
        while(i<=h)
        {
            if(s[i][j] == '#')break;

            s[i][j] = '1';
            i++;
        }
        i = a,j = b;
        while(j<=w)
        {
            if(s[i][j] == '#')break;

            s[i][j] = '1';
            j++;
        }
        i = a,j = b;
        while(j)
        {
            if(s[i][j] == '#')break;

            s[i][j] = '1';
            j--;
        }
    }

    for(i=1; i<=h; i++)
    {
        for(j=1; j<=w; j++)
        {
            if(s[i][j]!='1')no++;
        }
    }


    cout << (h*w)-no << endl;
}
