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

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

i = A("i")
k = B("k")
b = A("b")

i.q = b
k.w = i
b.q = i
assert k.w.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

i = A("i")
k = B("k")
b = A("b")

i.q = b
k.w = i
b.q = i
assert k.w.q.q.txt == "i"