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

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

i = A("i")
a = B("a")
h = A("h")
e = A("e")

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

i = A("i")
a = B("a")
h = A("h")
e = A("e")

i.q = e
a.x = i
h.q = i
e.q = h
assert e.q.q.q.q.txt == "h"