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

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

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

b = A("b")
c = B("c")
m = C("m")
d = B("d")
i = A("i")
g = B("g")
k = A("k")
n = C("n")
a = B("a")
j = A("j")

b.u = n
c.q = d
m.r = k
m.q = n
m.w = g
d.q = a
i.u = n
g.q = a
k.u = n
n.r = b
n.q = m
n.w = c
a.q = c
j.u = m
assert j.u.q.w.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

b = A("b")
c = B("c")
m = C("m")
d = B("d")
i = A("i")
g = B("g")
k = A("k")
n = C("n")
a = B("a")
j = A("j")

b.u = n
c.q = d
m.r = k
m.q = n
m.w = g
d.q = a
i.u = n
g.q = a
k.u = n
n.r = b
n.q = m
n.w = c
a.q = c
j.u = m
assert j.u.q.w.q.q.q.q.q.txt == "a"