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

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

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

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

m.y = c
c.s = n
c.w = m
e.w = m
e.s = m
a.w = m
a.s = m
n.s = c
n.w = m
g.w = m
g.s = m
assert a.s.y.w.y.w.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

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

m.y = c
c.s = n
c.w = m
e.w = m
e.s = m
a.w = m
a.s = m
n.s = c
n.w = m
g.w = m
g.s = m
assert a.s.y.w.y.w.y.txt == "c"