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

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

h = A("h")
i = B("i")
a = B("a")
k = A("k")
b = A("b")
g = B("g")
m = A("m")

h.t = k
i.u = g
a.u = g
k.t = b
b.t = k
g.u = a
m.t = b
assert i.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

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

h = A("h")
i = B("i")
a = B("a")
k = A("k")
b = A("b")
g = B("g")
m = A("m")

h.t = k
i.u = g
a.u = g
k.t = b
b.t = k
g.u = a
m.t = b
assert i.u.u.u.txt == "g"