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

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

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

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

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

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

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

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

i.x = f
m.t = f
f.p = i
f.z = m
assert m.t.z.t.txt == "f"