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

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

n = A("n")
a = B("a")
i = B("i")
e = B("e")
b = B("b")
m = A("m")

n.x = m
n.y = m
a.w = e
i.w = b
e.w = b
b.w = e
m.x = n
m.y = n
assert b.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.y: A = None
        self.txt = txt

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

n = A("n")
a = B("a")
i = B("i")
e = B("e")
b = B("b")
m = A("m")

n.x = m
n.y = m
a.w = e
i.w = b
e.w = b
b.w = e
m.x = n
m.y = n
assert b.w.w.w.w.txt == "b"