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.u: A = None
        self.o: A = None
        self.txt = txt

g = A("g")
h = B("h")
c = C("c")
d = B("d")

g.z = d
h.u = c
c.u = g
c.o = g
d.u = c
assert h.u.o.z.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.u: A = None
        self.o: A = None
        self.txt = txt

g = A("g")
h = B("h")
c = C("c")
d = B("d")

g.z = d
h.u = c
c.u = g
c.o = g
d.u = c
assert h.u.o.z.txt == "d"