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

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

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

i.w = d
i.q = n
d.x = i
n.w = d
n.q = i
assert d.x.q.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.q: A = None
        self.txt = txt

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

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

i.w = d
i.q = n
d.x = i
n.w = d
n.q = i
assert d.x.q.w.txt == "d"