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

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

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

j = A("j")
l = B("l")
m = C("m")
k = A("k")
h = C("h")

j.p = m
l.w = k
l.r = j
m.s = l
k.p = m
h.s = l
assert l.w.p.s.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

j = A("j")
l = B("l")
m = C("m")
k = A("k")
h = C("h")

j.p = m
l.w = k
l.r = j
m.s = l
k.p = m
h.s = l
assert l.w.p.s.r.p.txt == "m"