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

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

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

m = A("m")
a = B("a")
k = C("k")
b = C("b")
f = A("f")
i = C("i")
l = B("l")
c = C("c")

m.z = c
a.w = m
a.r = b
a.p = b
k.v = m
b.v = m
f.z = i
i.v = f
l.w = m
l.r = i
l.p = i
c.v = f
assert k.v.z.v.z.v.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.txt = txt

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

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

m = A("m")
a = B("a")
k = C("k")
b = C("b")
f = A("f")
i = C("i")
l = B("l")
c = C("c")

m.z = c
a.w = m
a.r = b
a.p = b
k.v = m
b.v = m
f.z = i
i.v = f
l.w = m
l.r = i
l.p = i
c.v = f
assert k.v.z.v.z.v.txt == "f"