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.p: A = None
        self.u: B = None
        self.txt = txt

d = A("d")
c = B("c")
m = C("m")
k = C("k")

d.z = c
c.z = d
m.p = d
m.u = c
k.p = d
k.u = c
assert d.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.p: A = None
        self.u: B = None
        self.txt = txt

d = A("d")
c = B("c")
m = C("m")
k = C("k")

d.z = c
c.z = d
m.p = d
m.u = c
k.p = d
k.u = c
assert d.z.z.z.txt == "c"