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

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

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

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

l = A("l")
a = B("a")
d = C("d")
h = D("h")
g = A("g")
m = A("m")
e = D("e")

l.w = h
a.z = d
d.r = h
d.x = a
h.z = d
g.w = e
m.w = h
e.z = d
assert h.z.x.z.r.z.txt == "
class A:
    def __init__(self, txt: str):
        self.w: D = None
        self.txt = txt

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

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

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

l = A("l")
a = B("a")
d = C("d")
h = D("h")
g = A("g")
m = A("m")
e = D("e")

l.w = h
a.z = d
d.r = h
d.x = a
h.z = d
g.w = e
m.w = h
e.z = d
assert h.z.x.z.r.z.txt == "d"