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

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

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

m.s = d
g.o = a
i.s = g
h.s = a
k.s = d
d.o = g
j.s = d
a.o = d
e.s = d
assert h.s.o.o.o.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: B = None
        self.txt = txt

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

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