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

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

n = A("n")
k = B("k")
a = A("a")
e = A("e")
i = A("i")
d = B("d")
c = A("c")
h = A("h")

n.q = i
k.o = d
a.q = i
e.q = h
i.q = a
d.o = k
c.q = i
h.q = n
assert a.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.o: B = None
        self.txt = txt

n = A("n")
k = B("k")
a = A("a")
e = A("e")
i = A("i")
d = B("d")
c = A("c")
h = A("h")

n.q = i
k.o = d
a.q = i
e.q = h
i.q = a
d.o = k
c.q = i
h.q = n
assert a.q.q.q.txt == "i"