#include <iostream>
#include <vector>
#include <unordered_set>
enum RowType {
ROW,
COL
};
typedef unsigned long long ulonglong;
typedef struct Operation {
long long time;
long long color;
} Operation;
/*
void print_op(std::vector<Operation> arr) {
for (Operation cur : arr) {
//std::cout << cur.idx << ' ' << cur.time << ' ' << cur.color << std::endl;
}
}
void print_colors(ulonglong* colors, long size) {
for (long i = 0; i < size; i++) {
//std::cout << colors[i] << ' ';
}
//std::cout << std::endl;
}*/
ulonglong hgt, wid, color_count, operation_count;
int main() {
long long time = 0;
std::vector<Operation> row_operations;
std::vector<Operation> col_operations;
ulonglong row_count = 0;
ulonglong col_count = 0;
std::unordered_set<ulonglong> existing_rows;
std::unordered_set<ulonglong> existing_cols;
std::cin >> hgt >> wid >> color_count >> operation_count;
existing_rows.reserve(operation_count);
existing_cols.reserve(operation_count);
row_operations.reserve(operation_count);
col_operations.reserve(operation_count);
char rows[20001];
ulonglong indices[20001];
ulonglong colors[20001];
/*std::cout << "before: " << std::endl;
print_colors(colors, operation_count);*/
for (ulonglong i = 0; i < operation_count; i++) {
char c;
ulonglong idx, color;
std::cin >> c >> idx >> color;
rows[i] = c;
indices[i] = idx;
colors[i] = color - 1;
}
/*std::cout << "after: " << std::endl;
print_colors(colors, operation_count);
std::cout << std::endl;*/
// <-------------------- NO CRASH
char last_row = 'Z';
for (long i = operation_count - 1; i >= 0; i--) {
char row = rows[i];
ulonglong idx = indices[i];
long long color = colors[i];
//std::cout << "row: " << row << ", idx: " << idx << ", color: " << color << std::endl;
if (row != last_row) { time++; }
if (row == 'R') {
bool was_inserted = existing_rows.insert(idx).second;
if (was_inserted) {
row_count++;
row_operations.push_back({
time, color
});
//}
} else {
bool was_inserted = existing_cols.insert(idx).second;
if (was_inserted) {
col_count++;
col_operations.push_back({
time, color
});
}
}
last_row = row;
}
// <---------------------- CRASH
std::cout << "intentionally wrong answer";
return 0;
//print_op(row_operations);
//print_op(col_operations);
long long rows_left_unmodified = hgt - row_count;
//std::cout << "hgt: " << hgt << ", row_count: " << row_count << ", rows left unmodified: " << rows_left_unmodified << std::endl;
long long cols_left_unmodified = wid - col_count;
//std::cout << "wid: " << wid << ", col_count: " << col_count << ", cols left unmodified: " << cols_left_unmodified << std::endl;
ulonglong colors_sum[20001];
for (ulonglong i = 0; i < color_count; i++) {
colors_sum[i] = 0;
}
for (Operation operation: row_operations) {
colors_sum[operation.color] += cols_left_unmodified;
}
for (Operation operation: col_operations) {
colors_sum[operation.color] += rows_left_unmodified;
}
// Exceptions:
// - no operations are defined
// - only rows are given
// - only cols are given
// Ignore if exception moment
if (col_count && row_count) {
time = 0;
RowType cur_type;
long long row_index = 0;
long long row_length = row_count - 1;
long long col_index = 0;
long long col_length = col_count - 1;
if (row_operations[0].time < col_operations[0].time) {
time = row_operations[row_index].time;
cur_type = RowType::ROW;
} else {
time = col_operations[col_index].time;
cur_type = RowType::COL;
}
while (row_length >= 0 && col_length >= 0) {
if (cur_type == RowType::ROW) {
if (row_length < 0) {
break;
}
Operation row = row_operations[row_index];
//std::cout << "ROW " << row_index << ", color: " << row.color << ", time: " << time << ", rowtime: " << row.time << std::endl;
if (time < row.time) { time++; cur_type = RowType::COL; continue; }
//std::cout << "Add " << col_length + 1 << " to " << row.color << std::endl;
colors_sum[row.color] += col_length + 1;
row_index++;
row_length--;
} else {
if (col_length < 0) {
break;
}
Operation col = col_operations[col_index];
//std::cout << "COL " << col_index << ", color: " << col.color << ", time: " << time << ", rowtime: " << col.time << std::endl;
if (time < col.time) { time++; cur_type = RowType::ROW; continue; }
//std::cout << "Add " << row_length + 1 << " to " << col.color << std::endl;
colors_sum[col.color] += row_length + 1;
col_index++;
col_length--;
}
}
}
// print
for (ulonglong i = 0; i < color_count; i++) {
std::cout << colors_sum[i] << ' ';
}
std::cout.flush();
return 0;
}