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.x: A = None
        self.txt = txt

m = A("m")
k = B("k")
h = A("h")
f = B("f")
a = A("a")
e = A("e")
c = B("c")

m.s = e
k.o = c
k.x = h
h.s = e
f.o = c
f.x = e
a.s = h
e.s = a
c.o = f
c.x = e
assert m.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.x: A = None
        self.txt = txt

m = A("m")
k = B("k")
h = A("h")
f = B("f")
a = A("a")
e = A("e")
c = B("c")

m.s = e
k.o = c
k.x = h
h.s = e
f.o = c
f.x = e
a.s = h
e.s = a
c.o = f
c.x = e
assert m.s.s.s.s.txt == "e"