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

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

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

l = A("l")
f = B("f")
b = C("b")
i = B("i")
c = C("c")
m = C("m")
j = B("j")
d = A("d")
k = B("k")
g = C("g")

l.s = g
l.u = c
f.s = l
f.p = b
b.w = j
i.s = d
i.p = b
c.w = i
m.w = i
j.s = d
j.p = m
d.s = g
d.u = m
k.s = l
k.p = c
g.w = i
assert b.w.s.s.w.p.w.p.w.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.u: C = None
        self.txt = txt

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

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

l = A("l")
f = B("f")
b = C("b")
i = B("i")
c = C("c")
m = C("m")
j = B("j")
d = A("d")
k = B("k")
g = C("g")

l.s = g
l.u = c
f.s = l
f.p = b
b.w = j
i.s = d
i.p = b
c.w = i
m.w = i
j.s = d
j.p = m
d.s = g
d.u = m
k.s = l
k.p = c
g.w = i
assert b.w.s.s.w.p.w.p.w.s.s.txt == "g"