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

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

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

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

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

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

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

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

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

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

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