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

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

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

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

n = A("n")
h = B("h")
d = C("d")
j = D("j")
e = B("e")

n.z = e
h.w = n
h.s = j
h.v = d
h.u = e
d.w = n
j.w = e
e.w = n
e.s = j
e.v = d
e.u = h
assert n.z.s.w.s.w.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

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

n = A("n")
h = B("h")
d = C("d")
j = D("j")
e = B("e")

n.z = e
h.w = n
h.s = j
h.v = d
h.u = e
d.w = n
j.w = e
e.w = n
e.s = j
e.v = d
e.u = h
assert n.z.s.w.s.w.txt == "e"