#include <stdio.h>

typedef struct TreeNode {
    char val;
    struct TreeNode* left;
    struct TreeNode* right;
} TreeNode;

TreeNode* BuildTree(char* str, int* index) {
    if (str[*index] == '\0' || str[*index] == '#') {
        (*index)++;
        return NULL;
    }
    TreeNode* Node = (TreeNode*)malloc(sizeof(TreeNode));
    Node->val = str[*index];
    (*index)++;
    Node->left = BuildTree(str, index);
    Node->right = BuildTree(str, index);
    return Node;
}

void Intravel(TreeNode* Tree) {
    if (Tree == NULL)
        return;
    Intravel(Tree->left);
    printf("%c ", Tree->val);
    Intravel(Tree->right);
}

int main() {
    char str[101];
    while (scanf("%s", str) != EOF) { // 注意 while 处理多个 case
        int index = 0;
        TreeNode* Tree = BuildTree(str, &index);
        Intravel(Tree);
    }
    return 0;
}