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

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

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

g = A("g")
h = B("h")
i = C("i")
a = A("a")
b = C("b")
f = C("f")
d = B("d")
m = C("m")
k = C("k")

g.u = h
h.o = i
i.y = d
i.s = g
a.u = d
b.y = h
b.s = a
f.y = d
f.s = a
d.o = i
m.y = d
m.s = a
k.y = h
k.s = g
assert a.u.o.y.o.y.o.s.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

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

g = A("g")
h = B("h")
i = C("i")
a = A("a")
b = C("b")
f = C("f")
d = B("d")
m = C("m")
k = C("k")

g.u = h
h.o = i
i.y = d
i.s = g
a.u = d
b.y = h
b.s = a
f.y = d
f.s = a
d.o = i
m.y = d
m.s = a
k.y = h
k.s = g
assert a.u.o.y.o.y.o.s.txt == "g"