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

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

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

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

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

n.z = d
b.u = n
b.s = d
d.t = a
a.v = m
k.v = c
c.u = n
c.s = d
m.u = n
m.s = d
assert k.v.s.t.v.s.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.txt = txt

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

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

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

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

n.z = d
b.u = n
b.s = d
d.t = a
a.v = m
k.v = c
c.u = n
c.s = d
m.u = n
m.s = d
assert k.v.s.t.v.s.txt == "d"