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

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

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

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

k = A("k")
h = B("h")
n = C("n")
a = D("a")
d = B("d")
m = A("m")

k.x = n
h.x = d
h.v = a
n.z = k
n.w = a
a.p = h
a.z = m
d.x = h
d.v = a
m.x = n
assert h.x.x.v.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

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

k = A("k")
h = B("h")
n = C("n")
a = D("a")
d = B("d")
m = A("m")

k.x = n
h.x = d
h.v = a
n.z = k
n.w = a
a.p = h
a.z = m
d.x = h
d.v = a
m.x = n
assert h.x.x.v.p.txt == "h"