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

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

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

n = A("n")
m = B("m")
g = C("g")
d = B("d")
c = C("c")
a = A("a")
b = B("b")

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

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

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

n = A("n")
m = B("m")
g = C("g")
d = B("d")
c = C("c")
a = A("a")
b = B("b")

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