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

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

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

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

h = A("h")
e = B("e")
i = C("i")
d = D("d")

h.s = e
h.y = e
h.o = e
e.u = d
i.o = e
i.x = d
i.z = h
i.p = h
d.z = h
d.v = e
assert h.o.u.v.u.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.y: B = None
        self.o: B = None
        self.txt = txt

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

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

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

h = A("h")
e = B("e")
i = C("i")
d = D("d")

h.s = e
h.y = e
h.o = e
e.u = d
i.o = e
i.x = d
i.z = h
i.p = h
d.z = h
d.v = e
assert h.o.u.v.u.txt == "d"