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

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

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

j.y = d
i.s = d
d.y = j
assert j.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

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

j.y = d
i.s = d
d.y = j
assert j.y.y.y.txt == "d"