import java.io.*;
import java.util.*;
class Solution {
static int lastIndex;
static int[] ak;
static int i;
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = 10;
StringBuilder sb = new StringBuilder();
for (int test_case = 1; test_case <= T; test_case++) {
int N = Integer.parseInt(br.readLine());
String[] tree = new String[N + 1];
lastIndex = N;
ak = new int[N];
for (int i = 1; i < tree.length; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
tree[Integer.parseInt(st.nextToken())] = st.nextToken();
}
i = 0;
int result = 1;
dfsByInOrder(1, tree);
for (int i = 0; i < ak.length - 1; i++) {
if (ak[i] == ak[i + 1])
result = 0;
}
if (ak[0] != 0 || ak[ak.length - 1] != 0) {
result = 0;
}
sb.append("#").append(test_case).append(" ").append(result).append("\n");
}
System.out.println(sb);
}
static void dfsByInOrder(int current, String[] node) {
if (current * 2 <= lastIndex) {
dfsByInOrder(current * 2, node);
}
if ("0123456789".contains(node[current])) {
ak[i++] = 0;
} else {
ak[i++] = 1;
}
if (current * 2 + 1 <= lastIndex) {
dfsByInOrder(current * 2 + 1, node);
}
}
}