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

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

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

i = A("i")
d = B("d")
f = C("f")

i.z = f
d.p = i
f.x = d
f.p = d
assert f.x.p.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.txt = txt

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

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

i = A("i")
d = B("d")
f = C("f")

i.z = f
d.p = i
f.x = d
f.p = d
assert f.x.p.z.txt == "f"