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

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

m = A("m")
j = B("j")
c = B("c")

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

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

m = A("m")
j = B("j")
c = B("c")

m.x = c
j.u = m
j.w = c
c.u = m
c.w = j
assert j.w.u.x.txt == "c"