#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>

class CountBit {
	std::vector<int> vec;
public:
	CountBit(int size) : vec(size, 0) {};
	void increment(int position) {
		while (position < vec.size()) {
			vec[position]++;
			position += ((position + 1) & ~position);
		}
	}
	void decrement(int position) {
		while (position < vec.size()) {
			vec[position]--;
			position += ((position + 1) & ~position);
		}
	}
	int operator[](int position) const {
		int result = 0;
		while (position >= 0) {
			result += vec[position];
			position -= ((position + 1) & ~position);
		}
		return result;
	}
};

class Count2DBit {
	std::vector<CountBit> vec;
public:
	Count2DBit(int height, int width) : vec(height, CountBit(width)) {};
	void increment(int x, int y) {
		while (y < vec.size()) {
			vec[y].increment(x);
			y += ((y + 1) & ~y);
		}
	}
	void decrement(int x, int y) {
		while (y < vec.size()) {
			vec[y].decrement(x);
			y += ((y + 1) & ~y);
		}
	}
	int apply(int x, int y) {
		int result = 0;
		while (y >= 0) {
			result += vec[y][x];
			y -= ((y + 1) & ~y);
		}
		return result;
	}
};
int main() {
	int height, width, bake_time, q; std::cin >> height >> width >> bake_time >> q;
	Count2DBit bake(height, width), baking(height, width);
	std::vector<std::vector<int>> put_time(height, std::vector<int>(width, -1));
	std::queue<std::tuple<int, int, int>> delay;
	for (auto _i = 0; _i < q; ++_i) {
		int t, c, h, w; std::cin >> t >> c >> h >> w; --h; --w;
		switch (c) {
		case 0:
			if (put_time[h][w] == -1) {
				put_time[h][w] = t;
				baking.increment(w, h);
				delay.push(std::make_tuple(t, h, w));
			}
			break;
		case 1:
			if (put_time[h][w] != -1 && put_time[h][w] + bake_time <= t) {
				put_time[h][w] = -1;
				bake.decrement(w, h);
			}
			break;
		default: int h2, w2; std::cin >> h2 >> w2; --h2; --w2;
			while (!delay.empty() && std::get<0>(delay.front()) + bake_time <= t) {
				auto time = std::get<0>(delay.front());
				auto y = std::get<1>(delay.front());
				auto x = std::get<2>(delay.front());
				delay.pop();
				baking.decrement(x, y);
				bake.increment(x, y);
			}
			std::cout << (bake.apply(w2, h2) - bake.apply(w - 1, h2) - bake.apply(w2, h - 1) + bake.apply(w - 1, h - 1)) << ' ' << (baking.apply(w2, h2) - baking.apply(w - 1, h2) - baking.apply(w2, h - 1) + baking.apply(w - 1, h - 1)) << '\n';
			break;
		}
	}
}
