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

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

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

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

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

f.z = g
a.s = f
a.p = h
e.x = h
e.z = h
e.v = a
e.y = f
h.z = a
h.r = a
h.t = e
h.u = e
g.s = f
g.p = h
d.x = h
d.z = h
d.v = g
d.y = f
assert e.z.t.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

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

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

f.z = g
a.s = f
a.p = h
e.x = h
e.z = h
e.v = a
e.y = f
h.z = a
h.r = a
h.t = e
h.u = e
g.s = f
g.p = h
d.x = h
d.z = h
d.v = g
d.y = f
assert e.z.t.z.z.txt == "a"