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

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

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

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

a.o = h
a.q = e
n.u = a
h.r = n
h.q = i
e.o = h
e.q = a
i.u = e
assert i.u.q.q.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.q: A = None
        self.txt = txt

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

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

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

a.o = h
a.q = e
n.u = a
h.r = n
h.q = i
e.o = h
e.q = a
i.u = e
assert i.u.q.q.o.txt == "h"