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

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

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

d = A("d")
m = B("m")
h = C("h")

d.z = m
m.u = h
h.o = m
h.s = d
h.u = d
assert m.u.o.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: C = None
        self.txt = txt

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

d = A("d")
m = B("m")
h = C("h")

d.z = m
m.u = h
h.o = m
h.s = d
h.u = d
assert m.u.o.u.txt == "h"