class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.y: A = None
        self.w: B = None
        self.txt = txt

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

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

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

d = A("d")
l = B("l")
c = C("c")
h = D("h")
k = B("k")
a = D("a")
b = D("b")
f = A("f")
n = A("n")

d.x = n
d.y = n
d.w = k
l.s = c
c.p = l
c.r = l
h.t = l
k.s = c
a.t = k
b.t = l
f.x = d
f.y = n
f.w = k
n.x = d
n.y = d
n.w = k
assert d.x.w.s.r.s.r.s.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.y: A = None
        self.w: B = None
        self.txt = txt

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

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

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

d = A("d")
l = B("l")
c = C("c")
h = D("h")
k = B("k")
a = D("a")
b = D("b")
f = A("f")
n = A("n")

d.x = n
d.y = n
d.w = k
l.s = c
c.p = l
c.r = l
h.t = l
k.s = c
a.t = k
b.t = l
f.x = d
f.y = n
f.w = k
n.x = d
n.y = d
n.w = k
assert d.x.w.s.r.s.r.s.p.s.txt == "c"