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

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

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

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

h.q = a
h.y = j
h.u = j
d.w = k
d.p = g
j.w = n
j.x = g
n.q = i
n.y = j
n.u = j
a.w = b
a.p = n
b.w = k
b.p = h
i.w = d
i.p = n
k.w = b
k.p = n
g.q = i
g.y = j
g.u = j
assert a.w.w.w.p.y.x.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.y: C = None
        self.u: C = None
        self.txt = txt

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

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

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

h.q = a
h.y = j
h.u = j
d.w = k
d.p = g
j.w = n
j.x = g
n.q = i
n.y = j
n.u = j
a.w = b
a.p = n
b.w = k
b.p = h
i.w = d
i.p = n
k.w = b
k.p = n
g.q = i
g.y = j
g.u = j
assert a.w.w.w.p.y.x.q.p.txt == "n"