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

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

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

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

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

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

d.x = c
c.s = d
b.x = c
assert d.x.s.x.txt == "c"