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

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

a = A("a")
n = B("n")
m = B("m")
f = A("f")

a.r = f
a.u = f
n.w = m
m.w = n
f.r = a
f.u = a
assert m.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.u: A = None
        self.txt = txt

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

a = A("a")
n = B("n")
m = B("m")
f = A("f")

a.r = f
a.u = f
n.w = m
m.w = n
f.r = a
f.u = a
assert m.w.w.w.txt == "n"