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

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

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

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

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

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

d.r = b
e.x = d
b.x = d
assert b.x.r.x.txt == "d"