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

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

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

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

n = A("n")
g = B("g")
b = C("b")
i = D("i")
k = D("k")
h = A("h")
d = C("d")
e = C("e")

n.v = i
n.s = k
g.z = b
b.w = h
i.s = g
i.v = g
i.p = d
k.s = g
k.v = g
k.p = b
h.v = i
h.s = i
d.w = h
e.w = n
assert e.w.v.p.txt == "
class A:
    def __init__(self, txt: str):
        self.v: D = None
        self.s: D = None
        self.txt = txt

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

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

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

n = A("n")
g = B("g")
b = C("b")
i = D("i")
k = D("k")
h = A("h")
d = C("d")
e = C("e")

n.v = i
n.s = k
g.z = b
b.w = h
i.s = g
i.v = g
i.p = d
k.s = g
k.v = g
k.p = b
h.v = i
h.s = i
d.w = h
e.w = n
assert e.w.v.p.txt == "d"