rt
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const int N = 2e5 + 5, INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
int n, m, q, k;
int cnt[3][N], d[N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
cin >> n >> m >> q >> k;
while(q --) {
int op, x;
cin >> op >> x;
cnt[op][x] ++;
cnt[op][x] %= k;
}
for(int i = 0; i < n; i ++) {
d[cnt[1][i]] ++;
}
LL ans = 1ll * n * m;
for(int i = 1; i <= m; i ++) {
ans -= d[(k - cnt[2][i]) % k];
}
cout << ans << '\n';
return 0;
}