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

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

a = A("a")
h = B("h")
m = B("m")
k = B("k")
e = B("e")
b = A("b")

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

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

a = A("a")
h = B("h")
m = B("m")
k = B("k")
e = B("e")
b = A("b")

a.s = m
h.s = a
m.s = a
k.s = a
e.s = a
b.s = k
assert e.s.s.s.s.s.txt == "a"