class A:
    def __init__(self, txt: str):
        self.s: 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.y: B = None
        self.s: B = None
        self.txt = txt

m = A("m")
b = B("b")
d = C("d")

m.s = d
b.y = d
d.y = b
d.s = b
assert b.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.s: 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.y: B = None
        self.s: B = None
        self.txt = txt

m = A("m")
b = B("b")
d = C("d")

m.s = d
b.y = d
d.y = b
d.s = b
assert b.y.y.y.txt == "d"