#include <bits/stdc++.h>
using namespace std;
int main(){
    int H, W, N, M;
    cin >> H >> W >> N >> M;
    vector<int> A(N), B(N), C(M), D1(M);
    for(int i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }
    for(int i = 0; i < M; i++) {
        cin >> C[i] >> D1[i];
        C[i]--;
        D1[i]--;
    }
    vector<vector<char>> field(H, vector<char>(W, '.'));
    for(int i = 0; i < N; i++){
        field[A[i]][B[i]] = 'o';
    }
    for(int i = 0; i < M; i++){
        field[C[i]][D1[i]] = '#';
    }
    vector<vector<int>> U(H, vector<int>(W)), L(H, vector<int>(W)), R(H, vector<int>(W)), D(H, vector<int>(W));
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(field[i][j] == 'o'){
                L[i][j] = 1;
            }
            else if(field[i][j] == '.'){
                if(j > 0) L[i][j] = L[i][j - 1];
            }
        }
        for(int j = W - 1; j >= 0; j--){
            if(field[i][j] == 'o'){
                R[i][j] = 1;
            }
            else if(field[i][j] == '.'){
                if(j + 1 < W) R[i][j] = R[i][j + 1];
            }
        }
    }
    for(int i = 0; i < W; i++){
        for(int j = 0; j < H; j++){
            if(field[j][i] == 'o'){
                U[j][i] = 1;
            }
            else if(field[j][i] == '.'){
                if(j > 0) U[j][i] = U[j - 1][i];
            }
        }
        for(int j = H - 1; j >= 0; j--){
            if(field[j][i] == 'o'){
                D[j][i] = 1;
            }
            else if(field[j][i] == '.'){
                if(j + 1 < H) D[j][i] = D[j + 1][i];
            }
        }
    }
    int cnt = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(U[i][j] > 0 || D[i][j] > 0 || L[i][j] > 0 || R[i][j] > 0) cnt++;
        }
    }
    cout << cnt << endl;
}
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>

using namespace std;
 
#define ll long long int
#define f(i,l,n) for(int i=l;i<n;i++) 
#define E "\n"
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define vi(typ) vector<typ>
#define Ee cout<<"\n";




ll n,m;
vector<ll> graph[2005],visited(2005,0),dis(2005,0);
bool isvalid=0;
ll org,adj[2002][2002],val;
void dfs(ll node)
{
 // cout<<node<<E;
  for(auto x:graph[node])
  {
    
    if(x==org )
    {
      val=min(val,dis[node]+adj[node][x]);
      
    }
   // if(node==3) cout<<x<<" "<<val<<" "<<dis[node]<<" "<<adj[node][x]<<E;
    if(dis[node]+adj[node][x]<dis[x])
    {
      visited[x]=1;
      dis[x]=min(dis[x],adj[node][x]+dis[node]);
      dfs(x);
    }

  }
}

ll solve()
{
  
  cin >> n >> m;
  f(i,0,m)
  {
    ll x,y,c;
    cin >> x >> y >> c;
   
    if(adj[x][y]==0) 
    {
      adj[x][y]=c;
      graph[x].push_back(y);
    //  graph[y].push_back(x);
    }
    else adj[x][y]=min(adj[x][y],c);

  }

  f(i,1,n+1)
  {
    f(j,1,n+1) visited[j]=0,dis[j]=1e15;
    org=i,val=1e15;
    visited[i]=1;
    dis[i]=0;
    dfs(i);
    if(val==1e15) cout<<"-1\n";
    else cout<<val<<E;

  }

  return 0;  
}


int main()
{

   #ifndef ONLINE_JUDGE
      freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
      #endif
     ll t = 1;
     fast;
   //  cin >> t;
     while(t--)
     {
          int l=solve();
         // cout<<"hii\n";
     }

     return 0;
}