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

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

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

c = A("c")
n = B("n")
i = C("i")
f = C("f")

c.p = n
n.y = c
i.u = c
i.z = c
i.w = f
f.u = c
f.z = c
f.w = i
assert f.w.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

c = A("c")
n = B("n")
i = C("i")
f = C("f")

c.p = n
n.y = c
i.u = c
i.z = c
i.w = f
f.u = c
f.z = c
f.w = i
assert f.w.z.p.txt == "n"