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

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

m = A("m")
b = B("b")
d = A("d")
g = A("g")
i = A("i")
a = A("a")
e = B("e")
h = A("h")

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

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

m = A("m")
b = B("b")
d = A("d")
g = A("g")
i = A("i")
a = A("a")
e = B("e")
h = A("h")

m.s = b
b.o = a
d.s = b
g.s = e
i.s = e
a.s = b
e.o = g
h.s = b
assert g.s.o.s.o.s.o.s.o.txt == "g"