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

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

m = A("m")
h = B("h")
e = A("e")
l = A("l")
g = B("g")
j = B("j")

m.s = l
h.s = m
e.s = l
l.s = e
g.s = e
j.s = l
assert g.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.s: A = None
        self.txt = txt

m = A("m")
h = B("h")
e = A("e")
l = A("l")
g = B("g")
j = B("j")

m.s = l
h.s = m
e.s = l
l.s = e
g.s = e
j.s = l
assert g.s.s.s.txt == "e"