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

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

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

k = A("k")
f = B("f")
g = C("g")
j = B("j")
n = C("n")
m = B("m")

k.z = m
f.z = k
g.y = j
g.z = n
g.w = n
j.z = k
n.y = j
n.z = g
n.w = g
m.z = k
assert n.y.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

k = A("k")
f = B("f")
g = C("g")
j = B("j")
n = C("n")
m = B("m")

k.z = m
f.z = k
g.y = j
g.z = n
g.w = n
j.z = k
n.y = j
n.z = g
n.w = g
m.z = k
assert n.y.z.z.z.z.txt == "m"