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

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

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

a = A("a")
g = B("g")
c = C("c")
j = C("j")
m = A("m")

a.s = g
a.w = g
g.o = m
g.r = m
c.w = g
j.w = g
m.s = g
m.w = g
assert a.w.o.w.o.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.w: B = None
        self.txt = txt

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

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

a = A("a")
g = B("g")
c = C("c")
j = C("j")
m = A("m")

a.s = g
a.w = g
g.o = m
g.r = m
c.w = g
j.w = g
m.s = g
m.w = g
assert a.w.o.w.o.txt == "m"