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

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

h = A("h")
e = B("e")
f = B("f")
i = B("i")

h.z = f
e.u = i
f.u = i
i.u = e
assert i.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

h = A("h")
e = B("e")
f = B("f")
i = B("i")

h.z = f
e.u = i
f.u = i
i.u = e
assert i.u.u.u.txt == "e"