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

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

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

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

j = A("j")
d = B("d")
m = C("m")
e = D("e")
i = B("i")
h = B("h")
f = C("f")

j.t = f
j.x = d
j.z = i
d.w = h
d.v = f
m.t = e
m.x = e
m.s = j
e.w = m
i.w = d
i.v = m
h.w = i
h.v = m
f.t = e
f.x = e
f.s = j
assert e.w.s.t.s.t.s.z.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.x: B = None
        self.z: B = None
        self.txt = txt

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

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

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

j = A("j")
d = B("d")
m = C("m")
e = D("e")
i = B("i")
h = B("h")
f = C("f")

j.t = f
j.x = d
j.z = i
d.w = h
d.v = f
m.t = e
m.x = e
m.s = j
e.w = m
i.w = d
i.v = m
h.w = i
h.v = m
f.t = e
f.x = e
f.s = j
assert e.w.s.t.s.t.s.z.txt == "i"