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

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

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

n = A("n")
g = B("g")
d = C("d")
f = B("f")
j = C("j")
i = C("i")
h = A("h")

n.w = j
n.z = h
g.w = h
g.y = f
g.x = f
d.s = h
d.w = h
d.r = g
f.w = n
f.y = g
f.x = g
j.s = h
j.w = n
j.r = g
i.s = n
i.w = n
i.r = f
h.w = d
h.z = n
assert d.r.x.x.w.z.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.z: A = None
        self.txt = txt

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

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

n = A("n")
g = B("g")
d = C("d")
f = B("f")
j = C("j")
i = C("i")
h = A("h")

n.w = j
n.z = h
g.w = h
g.y = f
g.x = f
d.s = h
d.w = h
d.r = g
f.w = n
f.y = g
f.x = g
j.s = h
j.w = n
j.r = g
i.s = n
i.w = n
i.r = f
h.w = d
h.z = n
assert d.r.x.x.w.z.w.w.txt == "n"