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

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

i = A("i")
d = B("d")
m = B("m")

i.r = d
i.w = m
d.r = i
m.r = i
assert m.r.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.w: B = None
        self.txt = txt

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

i = A("i")
d = B("d")
m = B("m")

i.r = d
i.w = m
d.r = i
m.r = i
assert m.r.w.r.txt == "i"