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

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

class C:
    def __init__(self, txt: str):
        self.r: A = None
        self.v: A = None
        self.txt = txt

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

d.s = g
d.z = c
c.x = d
c.o = d
m.r = d
m.v = d
g.x = d
g.o = d
assert d.z.o.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.z: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.r: A = None
        self.v: A = None
        self.txt = txt

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

d.s = g
d.z = c
c.x = d
c.o = d
m.r = d
m.v = d
g.x = d
g.o = d
assert d.z.o.s.txt == "g"