#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

class node{
    public:
    int data ;
    node*left;
    node*right;

    node( int d){
        data = d;
        left = NULL;
        right = NULL;
    }
};

node*temp = NULL;
node*buildtree(){
	string s;cin>>s;
	if(s=="false"){
		return NULL;
	}
	if(s=="true"){
		buildtree();
	}
	if(s!= "true"&&s!= "false"){
		node*root = new node(stoi(s));
		root->left = buildtree();
		root->right = buildtree();
		temp = root;
	}
	return temp;
}

vector<vector<int>>ans;
vector<int>res;

void rootToLeaf(node* root, int sum, int cs){
	if(root == NULL)return;

	res.push_back(root->data);
	cs += root->data;

	if(root->left == NULL and root->right == NULL and cs == sum){
		ans.push_back(res);
		res.pop_back();
		return;
	}

	rootToLeaf(root->left,sum,cs);
	rootToLeaf(root->right,sum,cs);
	res.pop_back();
}


int main() {
	node*root = buildtree();
	int k;
	cin >>k;
	int curSum = 0;

	rootToLeaf(root,k,curSum);
	
	for(auto v : ans){
		for(auto x : v)cout<<x<<" ";
		cout<<endl;
	}
	return 0;
}