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

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

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

n = A("n")
j = B("j")
k = C("k")
g = C("g")
m = B("m")
c = B("c")
a = A("a")
f = B("f")
h = B("h")
d = A("d")

n.w = a
n.r = h
n.q = d
j.q = a
k.u = g
k.p = g
k.x = h
g.u = k
g.p = k
g.x = c
m.q = n
c.q = d
a.w = n
a.q = n
a.r = j
f.q = a
h.q = d
d.w = n
d.q = n
d.r = j
assert g.x.q.r.q.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.r: B = None
        self.q: A = None
        self.txt = txt

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

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

n = A("n")
j = B("j")
k = C("k")
g = C("g")
m = B("m")
c = B("c")
a = A("a")
f = B("f")
h = B("h")
d = A("d")

n.w = a
n.r = h
n.q = d
j.q = a
k.u = g
k.p = g
k.x = h
g.u = k
g.p = k
g.x = c
m.q = n
c.q = d
a.w = n
a.q = n
a.r = j
f.q = a
h.q = d
d.w = n
d.q = n
d.r = j
assert g.x.q.r.q.w.w.txt == "a"