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

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

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

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

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

k.y = b
k.z = c
i.v = k
h.x = i
h.p = i
h.y = b
h.v = k
b.v = h
b.z = h
b.s = c
c.v = h
c.z = h
c.s = b
assert i.v.z.v.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.z: D = None
        self.txt = txt

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

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

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

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

k.y = b
k.z = c
i.v = k
h.x = i
h.p = i
h.y = b
h.v = k
b.v = h
b.z = h
b.s = c
c.v = h
c.z = h
c.s = b
assert i.v.z.v.txt == "h"