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

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

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

a = A("a")
k = B("k")
f = C("f")
c = B("c")
e = A("e")
d = A("d")
h = B("h")
l = C("l")
g = C("g")

a.o = g
k.u = h
k.x = e
f.s = d
c.u = h
c.x = d
e.o = g
d.o = f
h.u = c
h.x = d
l.s = e
g.s = a
assert l.s.o.s.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

a = A("a")
k = B("k")
f = C("f")
c = B("c")
e = A("e")
d = A("d")
h = B("h")
l = C("l")
g = C("g")

a.o = g
k.u = h
k.x = e
f.s = d
c.u = h
c.x = d
e.o = g
d.o = f
h.u = c
h.x = d
l.s = e
g.s = a
assert l.s.o.s.txt == "a"