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

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

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

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

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

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

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

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

b.w = d
h.t = b
h.y = c
c.r = d
c.p = m
c.o = b
j.w = d
d.r = g
d.p = n
d.o = j
g.r = c
g.p = j
g.o = j
n.w = c
m.w = d
assert m.w.r.r.p.w.o.txt == "j"