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

class B:
    def __init__(self, txt: str):
        self.y: D = None
        self.txt = txt

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

class D:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

h = A("h")
l = B("l")
b = C("b")
c = D("c")
g = E("g")
k = E("k")
a = D("a")
d = A("d")
i = A("i")
f = A("f")

h.w = b
l.y = a
b.r = f
c.s = b
g.z = b
g.v = l
k.z = b
k.v = l
a.s = b
d.w = b
i.w = b
f.w = b
assert h.w.r.w.r.w.r.w.r.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: D = None
        self.txt = txt

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

class D:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

h = A("h")
l = B("l")
b = C("b")
c = D("c")
g = E("g")
k = E("k")
a = D("a")
d = A("d")
i = A("i")
f = A("f")

h.w = b
l.y = a
b.r = f
c.s = b
g.z = b
g.v = l
k.z = b
k.v = l
a.s = b
d.w = b
i.w = b
f.w = b
assert h.w.r.w.r.w.r.w.r.w.txt == "b"