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

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

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

g = A("g")
m = B("m")
e = C("e")
i = A("i")
d = A("d")

g.s = e
m.u = i
m.o = e
e.s = d
e.o = g
i.s = e
d.s = e
assert e.o.s.o.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

g = A("g")
m = B("m")
e = C("e")
i = A("i")
d = A("d")

g.s = e
m.u = i
m.o = e
e.s = d
e.o = g
i.s = e
d.s = e
assert e.o.s.o.s.txt == "e"