class A:
    def __init__(self, txt: str):
        self.z: C = 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.p: A = None
        self.txt = txt

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

f.z = g
i.y = g
g.p = f
assert g.p.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = 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.p: A = None
        self.txt = txt

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

f.z = g
i.y = g
g.p = f
assert g.p.z.p.txt == "f"