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

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

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

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

g = A("g")
f = B("f")
c = C("c")
k = D("k")
b = D("b")
n = B("n")
e = A("e")
m = C("m")
h = A("h")
d = D("d")

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

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

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

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

g = A("g")
f = B("f")
c = C("c")
k = D("k")
b = D("b")
n = B("n")
e = A("e")
m = C("m")
h = A("h")
d = D("d")

g.v = d
f.t = h
f.p = e
c.s = e
c.t = e
k.w = f
b.w = f
n.t = g
n.p = e
e.v = d
m.s = h
m.t = g
h.v = k
d.w = n
assert e.v.w.p.v.txt == "d"