#include <bits/stdc++.h>

using namespace std;

int n, m;

int a[200010];
int b[200010];
int c[200010];
int f[200010];

class BIT {
public:
	static const int SIZE = 400010;
	int u[SIZE];
	void clear() {
		for (int i = 1; i <= m; i++) u[i] = 0;
	}
	void add(int x, int w) {
		while (x <= m) {
			u[x] += w;
			x += x & (-x);
		}
	}
	int get(int x) {
		int res = 0;
		while (x) {
			res += u[x];
			x -= x & (-x);
		}
		return res;
	}
}A, B;

int main()
{
	int cas = 0;
	while (scanf("%d", &n) != EOF) {
		printf("Case #%d:\n", ++cas);
		vector<int> Q;
		int tot = 0;
		for (int i = 1; i <= n; i++) {
			scanf("%d%d", a + i, b + i);
			if (a[i] == 0) {
				f[++tot] = i;
				c[i] = b[i] + tot;
				Q.push_back(b[i]);
				Q.push_back(c[i]);
			}
		}
		sort(Q.begin(), Q.end());
		Q.resize(unique(Q.begin(), Q.end()) - Q.begin());
		m = Q.size();
		for (int i = 1; i <= n; i++) {
			if (a[i] == 0) {
				b[i] = lower_bound(Q.begin(), Q.end(), b[i]) - Q.begin() + 1;
				c[i] = lower_bound(Q.begin(), Q.end(), c[i]) - Q.begin() + 1;
			}
		}
		A.clear(), B.clear();
		for (int i = 1; i <= n; i++) {
			if (a[i] == 0) {
				int ans = B.get(c[i]) - A.get(b[i] - 1);
				if (ans < 0) ans = 0;
				printf("%d\n", ans);
				A.add(b[i], +1);
				B.add(c[i], +1);
			}
			if (a[i] == 1) {
				int idx = f[b[i]];
				A.add(b[idx], -1);
				B.add(c[idx], -1);
			}
		}
	}
	return 0;
}

