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

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

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

m = A("m")
a = B("a")
n = C("n")
i = A("i")
c = C("c")
h = A("h")

m.q = i
a.q = i
a.r = c
n.r = a
n.t = a
n.o = c
i.q = m
c.r = a
c.t = a
c.o = n
h.q = i
assert n.o.o.t.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.q: A = None
        self.r: C = None
        self.txt = txt

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

m = A("m")
a = B("a")
n = C("n")
i = A("i")
c = C("c")
h = A("h")

m.q = i
a.q = i
a.r = c
n.r = a
n.t = a
n.o = c
i.q = m
c.r = a
c.t = a
c.o = n
h.q = i
assert n.o.o.t.q.q.txt == "m"