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

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

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

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

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

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

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