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

class B:
    def __init__(self, txt: str):
        self.w: C = None
        self.p: C = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

h = A("h")
m = B("m")
k = C("k")
f = D("f")
l = C("l")
a = B("a")

h.z = m
m.w = k
m.p = k
k.q = f
f.z = l
f.x = m
f.v = h
l.q = f
a.w = l
a.p = k
assert m.p.q.z.q.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.w: C = None
        self.p: C = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

h = A("h")
m = B("m")
k = C("k")
f = D("f")
l = C("l")
a = B("a")

h.z = m
m.w = k
m.p = k
k.q = f
f.z = l
f.x = m
f.v = h
l.q = f
a.w = l
a.p = k
assert m.p.q.z.q.x.p.txt == "k"