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

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

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

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

n.q = e
n.r = a
n.p = c
a.u = m
a.r = i
a.q = i
i.o = a
m.u = a
m.r = i
m.q = i
c.q = e
c.r = m
c.p = n
e.q = d
e.p = d
e.r = m
d.q = c
d.r = a
d.p = e
assert a.u.q.o.u.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.r: B = None
        self.p: A = None
        self.txt = txt

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

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

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

n.q = e
n.r = a
n.p = c
a.u = m
a.r = i
a.q = i
i.o = a
m.u = a
m.r = i
m.q = i
c.q = e
c.r = m
c.p = n
e.q = d
e.p = d
e.r = m
d.q = c
d.r = a
d.p = e
assert a.u.q.o.u.txt == "m"