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

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

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

n = A("n")
c = B("c")
d = C("d")
e = B("e")
h = A("h")
f = B("f")
a = B("a")
i = A("i")
k = C("k")
g = C("g")

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

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

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

n = A("n")
c = B("c")
d = C("d")
e = B("e")
h = A("h")
f = B("f")
a = B("a")
i = A("i")
k = C("k")
g = C("g")

n.u = f
c.q = n
c.v = g
c.x = d
d.w = e
e.q = i
e.v = k
e.x = k
h.u = c
f.q = i
f.v = g
f.x = g
a.q = n
a.v = d
a.x = d
i.u = f
k.w = a
g.w = f
assert g.w.x.w.txt == "f"