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

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

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

g = A("g")
a = B("a")
d = C("d")

g.y = a
a.z = g
d.z = a
d.s = a
assert g.y.z.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

g = A("g")
a = B("a")
d = C("d")

g.y = a
a.z = g
d.z = a
d.s = a
assert g.y.z.y.txt == "a"