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

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

g = A("g")
i = B("i")
h = B("h")
a = B("a")
m = A("m")
c = B("c")
l = A("l")

g.s = l
i.o = c
h.o = c
a.o = i
m.s = g
c.o = h
l.s = g
assert m.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

g = A("g")
i = B("i")
h = B("h")
a = B("a")
m = A("m")
c = B("c")
l = A("l")

g.s = l
i.o = c
h.o = c
a.o = i
m.s = g
c.o = h
l.s = g
assert m.s.s.s.s.s.txt == "g"