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

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

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

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

h = A("h")
b = B("b")
c = C("c")
a = D("a")
n = A("n")
i = A("i")

h.v = n
b.o = a
c.o = a
c.x = a
c.v = b
c.z = n
a.z = h
n.v = i
i.v = n
assert c.v.o.z.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

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

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

h = A("h")
b = B("b")
c = C("c")
a = D("a")
n = A("n")
i = A("i")

h.v = n
b.o = a
c.o = a
c.x = a
c.v = b
c.z = n
a.z = h
n.v = i
i.v = n
assert c.v.o.z.txt == "h"