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

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

a = A("a")
j = B("j")
d = A("d")

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

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

a = A("a")
j = B("j")
d = A("d")

a.x = j
a.r = d
j.s = d
d.x = j
d.r = a
assert a.r.x.s.txt == "d"