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

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

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

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

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

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

a.x = l
j.x = g
b.x = l
l.x = b
d.x = e
e.x = d
g.x = e
i.x = j
m.x = j
assert m.x.x.x.txt == "e"