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

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

a = A("a")
n = B("n")
e = A("e")

a.q = e
n.t = e
e.q = a
assert e.q.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.t: A = None
        self.txt = txt

a = A("a")
n = B("n")
e = A("e")

a.q = e
n.t = e
e.q = a
assert e.q.q.q.txt == "a"