human
Can you solve the below in PYTHON3?
You have an array of integers (initially empty).

You have to perform q queries. Each query is of one of two types: 

  * "1 x" — add the element x to the end of the array.

  * "2 x y" — replace all occurrences of x in the array with y. 


Find the resulting array after performing all the queries.

Input

The first line contains a single integer q (1 ≤ q ≤ 5 ⋅ 10^5) — the number of queries.

Next q lines contain queries (one per line). Each query is of one of two types: 

  * "1 x" (1 ≤ x ≤ 5 ⋅ 10^5).

  * "2 x y" (1 ≤ x, y ≤ 5 ⋅ 10^5). 


It's guaranteed that there is at least one query of the first type.

Output

In a single line, print k integers — the resulting array after performing all the queries, where k is the number of queries of the first type.

Examples

Input

7
1 3
1 1
2 1 2
1 2
1 1
1 2
2 1 3

Output

3 2 2 3 2 

Input

4
1 1
1 2
1 1
2 2 2

Output

1 2 1 

Input

8
2 1 4
1 1
1 4
1 2
2 2 4
2 4 3
1 2
2 2 7

Output

1 3 3 7 

Note

In the first example, the array changes as follows:

[] → [3] → [3, 1] → [3, 2] → [3, 2, 2] → [3, 2, 2, 1] → [3, 2, 2, 1, 2] → [3, 2, 2, 3, 2].

In the second example, the array changes as follows:

[] → [1] → [1, 2] → [1, 2, 1] → [1, 2, 1].

In the third example, the array changes as follows:

[] → [] → [1] → [1, 4] → [1, 4, 2] → [1, 4, 4] → [1, 3, 3] → [1, 3, 3, 2] → [1, 3, 3, 7].
assistant
#Here is Python code to find the resulting array after performing all the queries.

class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n))
    def find(self, a): #return parent of a. a and b are in same set if they have same parent
        acopy = a
        while a != self.parent[a]:
            a = self.parent[a]
        while acopy != a: #path compression
            self.parent[acopy], acopy = a, self.parent[acopy]
        return a
    def union(self, a, b): #union a and b
        self.parent[self.find(b)] = self.find(a)

def main():
    
    q = int(input())
    
    n = q
    size = 0
    parValue = [-1] * n # keep track of value of group
    uf = UnionFind(n) # group all indexes with same values together
    parIdx = dict() # parIdx[value] = index of parent with this value
    
    for _ in range(q):
        in_ = readIntArr()
        if len(in_) == 2:
            size += 1
            x = in_[1]
            if x in parIdx.keys():
                uf.union(size - 1, parIdx[x])
                newPar = uf.find(size - 1)
                parIdx[x] = newPar
                parValue[newPar] = x
            else:
                # make size - 1 the new parent of x
                parIdx[x] = size - 1
                parValue[size - 1] = x
        else:
            x, y = in_[1], in_[2]
            if x == y:
                continue
            if x in parIdx.keys():
                xPar = parIdx[x]
                del parIdx[x]
                if y in parIdx.keys(): # merge these 2 groups
                    yPar = parIdx[y]
                    uf.union(xPar, yPar)
                    newPar = uf.find(yPar)
                    parIdx[y] = newPar
                    parValue[newPar] = y
                else:
                    parIdx[y] = xPar
                    parValue[xPar] = y
        # print('parValue:{} parIdx:{} parents:{}'.format(
        #     parValue, parIdx, uf.parent))
    ans = [-1] * size
    for i in range(size):
        value = parValue[uf.find(i)]
        ans[i] = value
    oneLineArrayPrint(ans)
    
    return

import...