#include <iostream>
#include <stack>
using namespace std;
//Ejem 8
int main() {
stack <int> s1;
stack <int> s2;
int t, i, np, n;
cin >> t;
while(t>0){
cin >> i >> np >> n;
switch(i){
case 1: //Insertar
if(np==1) s1.push(n);
else s2.push(n);
break;
case 2: //Transferir
switch(np){
case 1:
while(n>0 && (!s1.empty())){
s2.push(s1.top());
s1.pop();
n--;
}
break;
case 2:
while(n>0 && (!s2.empty())){
s1.push(s2.top());
s2.pop();
n--;
}
}
}
t--;
}
while(!s1.empty()) { cout << s1.top() << ' '; s1.pop(); }
cout << '\n';
while(!s2.empty()) { cout << s2.top() << ' '; s2.pop(); }
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RhY2s+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Ci8vRWplbSA4CmludCBtYWluKCkgewoJc3RhY2sgPGludD4gczE7CglzdGFjayA8aW50PiBzMjsKCWludCB0LCBpLCBucCwgbjsKCWNpbiA+PiB0OwoJd2hpbGUodD4wKXsKCQljaW4gPj4gaSA+PiBucCA+PiBuOwoJCXN3aXRjaChpKXsKCQkJY2FzZSAxOiAvL0luc2VydGFyCgkJCQlpZihucD09MSkgczEucHVzaChuKTsKCQkJCWVsc2UgczIucHVzaChuKTsKCQkJCWJyZWFrOwoJCQljYXNlIDI6IC8vVHJhbnNmZXJpcgoJCQkJc3dpdGNoKG5wKXsKCQkJCQljYXNlIDE6CgkJCQkJCXdoaWxlKG4+MCAmJiAoIXMxLmVtcHR5KCkpKXsKCQkJCQkJCXMyLnB1c2goczEudG9wKCkpOwoJCQkJCQkJczEucG9wKCk7CgkJCQkJCQluLS07CgkJCQkJCX0KCQkJCQkJYnJlYWs7CgkJCQkJY2FzZSAyOgoJCQkJCQl3aGlsZShuPjAgJiYgKCFzMi5lbXB0eSgpKSl7CgkJCQkJCQlzMS5wdXNoKHMyLnRvcCgpKTsKCQkJCQkJCXMyLnBvcCgpOwoJCQkJCQkJbi0tOwoJCQkJCQl9CgkJCQl9CgkJfQoJCQoJCXQtLTsKCX0KCXdoaWxlKCFzMS5lbXB0eSgpKSB7IGNvdXQgPDwgczEudG9wKCkgPDwgJyAnOyBzMS5wb3AoKTsgfQoJY291dCA8PCAnXG4nOwoJd2hpbGUoIXMyLmVtcHR5KCkpIHsgY291dCA8PCBzMi50b3AoKSA8PCAnICc7IHMyLnBvcCgpOyB9CglyZXR1cm4gMDsKfQ==