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

i = A("i")
h = B("h")
k = C("k")

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

i = A("i")
h = B("h")
k = C("k")

i.s = h
i.y = k
h.y = k
k.p = h
assert h.y.p.y.txt == "k"