
class Solution:
	def operate(self):
		size = int(raw_input());
		self.data = [[0, -1, -1] for i in range(0, size+1)];

		while(size>1):
			[nodeFrom, nodeTo] = map(int, raw_input().split(" "));
			self.makeConnection(nodeFrom, nodeTo);
			size = size-1;

	def makeConnection(self, nodeFrom, nodeTo):
		if self.data[nodeFrom][_left] == -1:
			self.data[nodeFrom][_left] = nodeTo;
			return;
		self.data[nodeFrom][_right] = nodeTo;

	def findPath(self, fromNode, toNode):
		self.pathFromRoot(self, fromNode);
		self.pathFromRoot(self, toNode);
	
	def pathFromRoot(self, toNode):
		path = [1];
		while(len(path) != 0):
			
		pass;

	def printData(self):
		for item in self.data:
			print item

_value = 0;
_left = 1;
_right = 2;

if __name__ == '__main__':
	s = Solution();
	s.operate();
	s.printData();
	