import sys
sys.stdin = open('input.txt')


def check(x):
    if x > n:
        return
    if x * 2 <= n:
        check(x * 2)
    answer.append(tree[x])
    if x * 2 + 1 <= n:
        check(x * 2 + 1)


for tc in range(1, 11):
    n = int(input())
    tree = [0] * (n + 1)
    for _ in range(n):
        array = list(input().split())
        tree[int(array[0])] = array[1]
    answer = []
    check(1)
    final = ''.join(answer)
    print(f'#{tc} {final}')

9e15a97b9599f71e3f591360062b21966e0b7061
<mask token>


def check(x):
    if x > n:
        return
    if x * 2 <= n:
        check(x * 2)
    answer.append(tree[x])
    if x * 2 + 1 <= n:
        check(x * 2 + 1)


<mask token>

<mask token>


def check(x):
    if x > n:
        return
    if x * 2 <= n:
        check(x * 2)
    answer.append(tree[x])
    if x * 2 + 1 <= n:
        check(x * 2 + 1)


for tc in range(1, 11):
    n = int(input())
    tree = [0] * (n + 1)
    for _ in range(n):
        array = list(input().split())
        tree[int(array[0])] = array[1]
    answer = []
    check(1)
    final = ''.join(answer)
    print(f'#{tc} {final}')

<mask token>
sys.stdin = open('input.txt')


def check(x):
    if x > n:
        return
    if x * 2 <= n:
        check(x * 2)
    answer.append(tree[x])
    if x * 2 + 1 <= n:
        check(x * 2 + 1)


for tc in range(1, 11):
    n = int(input())
    tree = [0] * (n + 1)
    for _ in range(n):
        array = list(input().split())
        tree[int(array[0])] = array[1]
    answer = []
    check(1)
    final = ''.join(answer)
    print(f'#{tc} {final}')

import sys
sys.stdin = open('input.txt')


def check(x):
    if x > n:
        return
    if x * 2 <= n:
        check(x * 2)
    answer.append(tree[x])
    if x * 2 + 1 <= n:
        check(x * 2 + 1)


for tc in range(1, 11):
    n = int(input())
    tree = [0] * (n + 1)
    for _ in range(n):
        array = list(input().split())
        tree[int(array[0])] = array[1]
    answer = []
    check(1)
    final = ''.join(answer)
    print(f'#{tc} {final}')
