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

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

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

h = A("h")
g = B("g")
k = C("k")
e = B("e")
c = A("c")
m = C("m")
a = C("a")

h.w = g
g.w = a
g.r = a
g.z = e
k.z = g
k.t = e
e.w = a
e.z = g
e.r = m
c.w = e
m.z = g
m.t = e
a.z = g
a.t = e
assert a.t.r.t.r.t.z.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

h = A("h")
g = B("g")
k = C("k")
e = B("e")
c = A("c")
m = C("m")
a = C("a")

h.w = g
g.w = a
g.r = a
g.z = e
k.z = g
k.t = e
e.w = a
e.z = g
e.r = m
c.w = e
m.z = g
m.t = e
a.z = g
a.t = e
assert a.t.r.t.r.t.z.txt == "g"