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

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

j = A("j")
i = B("i")
h = B("h")
d = A("d")

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

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

j = A("j")
i = B("i")
h = B("h")
d = A("d")

j.t = i
i.z = h
i.u = d
h.z = i
h.u = d
d.t = h
assert i.z.u.t.u.txt == "d"