class UnionFind:
    def __init__(self, n):
        self.father = {}
        for i in range(1, n + 1):
            self.father[i] = i
        self.count = n

    def find(self, x):
        if x == self.father[x]:
            return x
        return self.find(self.father[x])

    def union(self, a, b):
        root_a = self.find(a)
        root_b = self.find(b)
        if root_a != root_b:
            self.father[root_a] = root_b
            self.count -= 1


class ConnectingGraph3:
    """
    @param a: An integer
    @param b: An integer
    @return: nothing
    """

    def __init__(self, n):
        # initialize your data structure here.
        self.uf = UnionFind(n)

    def connect(self, a, b):
        # write your code here
        self.uf.union(a, b)

    """
    @return: An integer
    """

    def query(self):
        # write your code here
        return self.uf.count