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

class B:
    def __init__(self, txt: str):
        self.p: C = None
        self.y: B = None
        self.o: B = None
        self.txt = txt

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

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

a.w = g
g.p = m
g.y = d
g.o = d
m.s = a
d.p = m
d.y = g
d.o = g
assert m.s.w.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.p: C = None
        self.y: B = None
        self.o: B = None
        self.txt = txt

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

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

a.w = g
g.p = m
g.y = d
g.o = d
m.s = a
d.p = m
d.y = g
d.o = g
assert m.s.w.p.s.txt == "a"