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

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

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

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

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

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

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

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

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

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

e.x = a
j.z = l
m.y = l
m.x = e
l.s = j
l.w = m
l.r = e
l.z = h
a.x = e
f.y = l
f.x = a
d.z = l
h.z = l
assert j.z.s.z.s.z.s.z.w.txt == "m"