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

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

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

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

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

d.p = c
d.r = b
d.w = n
i.p = c
i.x = m
c.t = d
c.s = d
c.p = i
c.x = b
n.u = d
m.u = d
b.t = d
b.s = d
b.p = k
b.x = c
k.p = c
k.x = m
assert k.x.u.w.u.w.u.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.r: C = None
        self.w: D = None
        self.txt = txt

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

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

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

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

d.p = c
d.r = b
d.w = n
i.p = c
i.x = m
c.t = d
c.s = d
c.p = i
c.x = b
n.u = d
m.u = d
b.t = d
b.s = d
b.p = k
b.x = c
k.p = c
k.x = m
assert k.x.u.w.u.w.u.txt == "d"