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

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

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

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

i.x = k
i.p = c
i.z = c
c.y = k
f.y = c
f.r = c
k.y = c
k.r = c
assert f.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.p: B = None
        self.z: B = None
        self.txt = txt

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

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

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

i.x = k
i.p = c
i.z = c
c.y = k
f.y = c
f.r = c
k.y = c
k.r = c
assert f.y.y.y.txt == "c"