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

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

n = A("n")
i = B("i")
b = A("b")
a = B("a")

n.z = b
i.q = n
b.z = n
a.q = n
assert i.q.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

n = A("n")
i = B("i")
b = A("b")
a = B("a")

n.z = b
i.q = n
b.z = n
a.q = n
assert i.q.z.z.txt == "n"