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

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

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

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

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

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

d.r = b
m.y = d
m.o = b
b.y = d
b.o = m
assert m.y.r.o.txt == "m"