#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int MOD = 1e9 + 7;

LL C[510];
LL dp[510][510];

void init()
{
	C[0] = C[1] = 1;
	for (int i = 2; i <= 500; i++) {
		for (int j = 0; j < i; j++) {
			C[i] += C[j] * C[i - j - 1] % MOD;
			C[i] %= MOD;
		}
	}
	dp[0][0] = 1;
	for (int i = 1; i <= 500; i++) {
		for (int j = 0; j <= 500; j++) {
			for (int k = 0; k <= j; k++) {
				dp[i][j] += dp[i - 1][j - k] * C[k] % MOD;
				dp[i][j] %= MOD;
			}
		}
	}
}

int fa[510];
int son[510][2];
int tot;
int col[510];
int cnt[510];

int node()
{
	++tot;
	cnt[tot] = son[tot][0] = son[tot][1] = 0;
	return tot;
}

int main()
{
	init();
	int cas = 0, n;
	while (scanf("%d", &n) != EOF) {
		int now = tot = 1;
		for (int i = 1; i <= n; i++) {
			int opt, x;
			scanf("%d", &opt);
			if (opt == 0) {
				now = fa[now];
			}
			else 
			if (opt <= 2) {
				if (son[now][opt - 1] == 0) {
					int next = node();
					son[now][opt - 1] = next;
					fa[next] = now;
					col[next] = col[now];
					cnt[col[next]]--;
				}
				now = son[now][opt - 1];
			}
			else {
				scanf("%d", &x);
				int next = node();
				son[now][opt - 3] = next;
				fa[next] = now;
				col[next] = next;
				cnt[col[next]] = x - 1;
			}
		}
		//cout << tot << endl;
		map<int, int> sum;
		for (int i = 1; i <= tot; i++) {
			if (son[i][0] == 0) sum[col[i]]++;
			if (son[i][1] == 0) sum[col[i]]++;
		}
		
		LL ans = 1;
		for (auto &it : sum) {
			//printf("%d %d\n", it.first, it.second);
			ans = ans * dp[it.second][cnt[it.first]] % MOD;
		}
		printf("Case #%d: %lld\n", ++cas, ans);
	}
	return 0;
}
