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

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

m = A("m")
b = B("b")
h = B("h")
d = B("d")
a = B("a")

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

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

m = A("m")
b = B("b")
h = B("h")
d = B("d")
a = B("a")

m.t = b
b.z = m
b.u = a
h.z = m
h.u = d
d.z = m
d.u = a
a.z = m
a.u = b
assert d.z.t.z.txt == "m"