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

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

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

b = A("b")
e = B("e")
d = C("d")
k = B("k")
n = C("n")

b.o = n
e.z = k
e.y = b
e.p = b
d.z = n
d.v = k
k.z = e
k.y = b
k.p = b
n.z = d
n.v = e
assert n.z.v.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

b = A("b")
e = B("e")
d = C("d")
k = B("k")
n = C("n")

b.o = n
e.z = k
e.y = b
e.p = b
d.z = n
d.v = k
k.z = e
k.y = b
k.p = b
n.z = d
n.v = e
assert n.z.v.z.z.txt == "k"