#include <bits/stdc++.h>
using namespace std;
struct TreeNode{
	int val;
	TreeNode* right;
	TreeNode* left;
	TreeNode(int val):left(nullptr),right(nullptr),val(val){};
};

void helper(int c ,int r , vector<tuple<int,int,int>>&t,TreeNode* root){
	if(root == nullptr)return;
	t.emplace_back(c,r,root->val);
	helper(c-1,r+1,t,root->left);
	helper(c+1,r+1,t,root->right);
}
vector<vector<int>>vertical(TreeNode* root){
	vector<tuple<int,int,int>>t;
	//c,r,val
	helper(0,0,t,root);
	sort(t.begin(),t.end());
	vector<vector<int>>ans;
	int prev = INT_MIN;
	for(auto [c,r,val]:t){
		vector<int>curr;
		if(prev != c){
		  ans.push_back({});
		  prev = c;
		}
		ans.back().push_back(val);
	}
	return ans;
}
TreeNode* buildTree(){
	int x;cin>>x;
	if(x==-1)return nullptr;
	TreeNode* root = new TreeNode(x);
	
	queue<TreeNode*>q;
	q.push(root);
	
	while(!q.empty()){
		auto u = q.front();
		q.pop();
		
		if(cin>>x && x!=-1){
			u->left = new TreeNode(x);
			q.push(u->left);
		}
		
			if(cin>>x && x!=-1){
			u->right = new TreeNode(x);
			q.push(u->right);
		}
	}
	return root;
}
int main() {
    TreeNode* root = buildTree();
    vector<vector<int>>ans = vertical(root);
    
    for(auto x : ans){
    	for(auto y : x){
    		cout<<y<<" ";
    	}
    	cout<<endl;
    }
	return 0;
}