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

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

j = A("j")
i = B("i")
n = A("n")
h = B("h")

j.q = n
i.x = h
i.q = j
n.q = j
h.x = i
h.q = j
assert h.q.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.x: B = None
        self.q: A = None
        self.txt = txt

j = A("j")
i = B("i")
n = A("n")
h = B("h")

j.q = n
i.x = h
i.q = j
n.q = j
h.x = i
h.q = j
assert h.q.q.q.q.txt == "n"