class A:
    def __init__(self, txt: str):
        self.w: B = 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.q: A = None
        self.u: C = None
        self.txt = txt

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

m.w = h
h.u = m
n.q = c
n.u = d
c.w = a
a.u = c
d.q = c
d.u = n
j.w = h
e.u = c
b.q = j
b.u = i
i.q = m
i.u = d
assert j.w.u.w.u.w.u.w.u.w.u.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = 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.q: A = None
        self.u: C = None
        self.txt = txt

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

m.w = h
h.u = m
n.q = c
n.u = d
c.w = a
a.u = c
d.q = c
d.u = n
j.w = h
e.u = c
b.q = j
b.u = i
i.q = m
i.u = d
assert j.w.u.w.u.w.u.w.u.w.u.txt == "m"