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

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

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

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

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

a.z = d
a.v = f
a.t = f
a.o = e
d.v = e
e.x = a
e.z = h
f.y = e
h.x = a
h.z = e
assert f.y.x.o.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.v: D = None
        self.t: D = None
        self.o: C = None
        self.txt = txt

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

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

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

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

a.z = d
a.v = f
a.t = f
a.o = e
d.v = e
e.x = a
e.z = h
f.y = e
h.x = a
h.z = e
assert f.y.x.o.z.z.txt == "e"