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

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

b = A("b")
m = B("m")
c = A("c")
j = B("j")
e = A("e")
i = B("i")

b.u = i
b.w = e
m.w = j
c.u = m
c.w = e
j.w = i
e.u = m
e.w = b
i.w = m
assert c.u.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.w: A = None
        self.txt = txt

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

b = A("b")
m = B("m")
c = A("c")
j = B("j")
e = A("e")
i = B("i")

b.u = i
b.w = e
m.w = j
c.u = m
c.w = e
j.w = i
e.u = m
e.w = b
i.w = m
assert c.u.w.w.w.w.w.txt == "i"