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

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

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

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

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

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

j.x = d
j.w = d
e.q = i
i.q = e
d.x = j
d.w = j
assert e.q.q.q.q.txt == "e"