class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

h = A("h")
c = B("c")
b = A("b")
k = A("k")
n = A("n")
g = B("g")
i = B("i")

h.u = k
c.y = b
b.u = h
k.u = n
n.u = k
g.y = h
i.y = h
assert i.y.u.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

h = A("h")
c = B("c")
b = A("b")
k = A("k")
n = A("n")
g = B("g")
i = B("i")

h.u = k
c.y = b
b.u = h
k.u = n
n.u = k
g.y = h
i.y = h
assert i.y.u.u.u.u.u.txt == "k"