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

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

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

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

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

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

j.t = b
j.x = d
b.r = j
b.s = j
d.t = b
d.x = j
assert j.x.x.t.txt == "b"