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

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

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

i = A("i")
n = B("n")
m = C("m")
c = C("c")
k = B("k")
d = C("d")
f = B("f")

i.v = k
n.r = k
n.p = c
m.s = i
m.w = d
c.s = i
c.w = d
k.r = n
k.p = c
d.s = i
d.w = c
f.r = n
f.p = m
assert k.r.p.s.v.r.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

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

i = A("i")
n = B("n")
m = C("m")
c = C("c")
k = B("k")
d = C("d")
f = B("f")

i.v = k
n.r = k
n.p = c
m.s = i
m.w = d
c.s = i
c.w = d
k.r = n
k.p = c
d.s = i
d.w = c
f.r = n
f.p = m
assert k.r.p.s.v.r.p.w.txt == "d"