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

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

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

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

h = A("h")
m = B("m")
d = C("d")
k = D("k")
j = B("j")

h.o = k
h.z = m
m.x = k
m.s = k
m.w = d
d.u = k
k.z = j
j.x = k
j.s = k
j.w = d
assert k.z.w.u.z.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.z: B = None
        self.txt = txt

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

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

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

h = A("h")
m = B("m")
d = C("d")
k = D("k")
j = B("j")

h.o = k
h.z = m
m.x = k
m.s = k
m.w = d
d.u = k
k.z = j
j.x = k
j.s = k
j.w = d
assert k.z.w.u.z.txt == "j"