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

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

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

d = A("d")
j = B("j")
f = C("f")
h = A("h")
e = B("e")
c = A("c")
a = C("a")
b = C("b")
g = A("g")

d.r = e
d.z = a
j.u = a
f.w = j
h.r = j
h.z = a
e.u = f
c.r = j
c.z = a
a.w = j
b.w = e
g.r = e
g.z = b
assert f.w.u.w.u.w.u.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.z: C = None
        self.txt = txt

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

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

d = A("d")
j = B("j")
f = C("f")
h = A("h")
e = B("e")
c = A("c")
a = C("a")
b = C("b")
g = A("g")

d.r = e
d.z = a
j.u = a
f.w = j
h.r = j
h.z = a
e.u = f
c.r = j
c.z = a
a.w = j
b.w = e
g.r = e
g.z = b
assert f.w.u.w.u.w.u.txt == "a"