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

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

m = A("m")
n = B("n")
e = B("e")

m.u = e
n.t = m
n.w = m
e.t = m
e.w = m
assert e.t.u.t.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

m = A("m")
n = B("n")
e = B("e")

m.u = e
n.t = m
n.w = m
e.t = m
e.w = m
assert e.t.u.t.txt == "m"