def merge_data(a, b):
    return [min(a[0],b[0]),max(a[1],b[1])]


def get_flowerbeds(n, data):
    data.sort()

    for i in range(n-1):
        if data[i+1][0] <= data[i][1]:
            data[i+1] = merge_data(data[i], data[i+1])
        else:
            print(*data[i])
            # result.append(data[i])
    print(*data[-1])
    # result.append(data[-1])
    # [1, 3], [2, 4] -> [1, 4]
    # [3, 5], [4, 6] -> [3, 6]
    # [3, 6], [5, 6] -> [3, 6]
    # [5, 6], [7, 10] -> [5, 6], [7, 10]
    # print(data)
    # return result
    # return result


n = int(input())

data = [''] * n
for i in range(n):
    data[i] = list(map(int,input().strip().split()))
    # data[i] = tuple(map(int,input().strip().split()))

# print(data)
get_flowerbeds(n, data)
# data.sort()
# print(data)
