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

class B:
    def __init__(self, txt: str):
        self.y: C = None
        self.z: E = None
        self.s: A = None
        self.p: A = None
        self.txt = txt

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

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

class E:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

a = A("a")
d = B("d")
n = C("n")
h = D("h")
f = E("f")

a.v = f
a.y = h
a.p = n
d.y = n
d.z = f
d.s = a
d.p = a
n.y = a
n.w = f
h.w = d
h.v = n
h.y = n
f.r = h
assert h.w.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.v: E = None
        self.y: D = None
        self.p: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: C = None
        self.z: E = None
        self.s: A = None
        self.p: A = None
        self.txt = txt

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

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

class E:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

a = A("a")
d = B("d")
n = C("n")
h = D("h")
f = E("f")

a.v = f
a.y = h
a.p = n
d.y = n
d.z = f
d.s = a
d.p = a
n.y = a
n.w = f
h.w = d
h.v = n
h.y = n
f.r = h
assert h.w.z.r.txt == "h"