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

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

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

h = A("h")
l = B("l")
m = C("m")
k = C("k")
g = B("g")
i = C("i")

h.y = i
l.v = h
l.u = g
m.s = g
k.s = g
g.v = h
g.u = l
i.s = g
assert k.s.v.y.s.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

h = A("h")
l = B("l")
m = C("m")
k = C("k")
g = B("g")
i = C("i")

h.y = i
l.v = h
l.u = g
m.s = g
k.s = g
g.v = h
g.u = l
i.s = g
assert k.s.v.y.s.txt == "g"