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

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

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

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

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

n.p = d
n.r = f
n.w = f
k.p = c
h.r = d
m.t = b
m.z = n
d.r = h
b.p = g
b.r = k
b.w = f
g.r = d
c.t = b
c.z = n
f.p = m
assert c.z.r.p.t.r.p.t.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.r: B = None
        self.w: B = None
        self.txt = txt

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

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

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

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

n.p = d
n.r = f
n.w = f
k.p = c
h.r = d
m.t = b
m.z = n
d.r = h
b.p = g
b.r = k
b.w = f
g.r = d
c.t = b
c.z = n
f.p = m
assert c.z.r.p.t.r.p.t.txt == "b"