1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define fi first
#define se second
#define vt vector
#define FOR(a, b, c)  for(int a=b; a<c; ++a)
#define all(a)     (a).begin(),(a).end()
#define sz(a)      (int)(a).size()

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi; 
typedef vector<ll> vll;
typedef pii PII;
typedef pll PLL;

constexpr ll nax = 2e5+6969, INF = 1e9+2137;
constexpr ld eps = 1e-9;

struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        size_t hash1 = hash<T1>{}(p.fi);
        size_t hash2 = hash<T2>{}(p.se);
        return hash1
               ^ (hash2 + 0x9e3779b9 + (hash1 << 6)
                  + (hash1 >> 2));
    }
};

int n, m, k, q; 
unordered_set<pair<int,int>, hash_pair> vis; 

int solve() {
    unordered_set<pair<int,int>, hash_pair> cur = vis; 

    while(true) {
        int start_size = cur.size(); 
        for(auto e: vis) {
            if(cur.find(e) == cur.end())
                continue;
            int x = e.fi, y = e.se; 
            if(cur.find(mp(x-1,y)) == cur.end() && cur.find(mp(x+1,y)) == cur.end()) {
                cur.erase(mp(x,y)); 
                continue;
            }
            if(cur.find(mp(x,y-1)) == cur.end() && cur.find(mp(x,y+1)) == cur.end()) {
                cur.erase(mp(x,y)); 
                continue;
            }
        }
        int end_size = cur.size(); 
        if(end_size == start_size) {
            // for(auto e: cur) {
            //     cout << e.fi << " " << e.se << "\n"; 
            // }
            // cout << "\n\n";
            // for(auto e: vis) {
            //     cout << e.fi << " " << e.se << "\n"; 
            // }


            return vis.size() - end_size; 
        }
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> m >> k >> q; 

    for(int i = 0; i < k; i++) {
        int a, b; 
        cin >> a >> b; 
        vis.insert(mp(a,b)); 
    }

    cout << solve() << "\n"; 

    for(int i = 0; i < q; i++) {
        int a, b; 
        cin >> a >> b; 
        if(vis.find(mp(a,b)) == vis.end()) {
            vis.insert(mp(a,b)); 
        }
        else {
            vis.erase(mp(a,b)); 
        }
        
        cout << solve() << "\n";
    }
    
    return 0;
}