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

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

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

class D:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

k = A("k")
n = B("n")
g = C("g")
m = D("m")
l = C("l")

k.r = l
k.p = l
n.r = g
n.p = m
g.s = l
m.x = n
l.s = g
assert k.p.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.p: C = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

k = A("k")
n = B("n")
g = C("g")
m = D("m")
l = C("l")

k.r = l
k.p = l
n.r = g
n.p = m
g.s = l
m.x = n
l.s = g
assert k.p.s.s.s.s.txt == "l"