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

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

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

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

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

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

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

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

h.y = d
h.u = d
d.u = h
k.s = h
assert k.s.y.u.txt == "h"