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

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

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

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

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

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

a.y = j
j.q = a
d.y = j
assert d.y.q.y.txt == "j"