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

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

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

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

k.s = d
k.p = d
d.y = h
d.v = k
h.s = k
h.x = k
assert h.s.s.y.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.p: B = None
        self.txt = txt

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

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

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

k.s = d
k.p = d
d.y = h
d.v = k
h.s = k
h.x = k
assert h.s.s.y.txt == "h"