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

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

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

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

n = A("n")
g = B("g")
h = C("h")
j = D("j")
l = B("l")
f = B("f")
d = C("d")
a = B("a")

n.r = g
g.p = n
g.z = d
h.s = d
h.r = n
j.u = d
j.y = n
j.w = n
l.p = n
l.z = h
f.p = n
f.z = d
d.s = h
d.r = n
a.p = n
a.z = d
assert a.p.r.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

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

n = A("n")
g = B("g")
h = C("h")
j = D("j")
l = B("l")
f = B("f")
d = C("d")
a = B("a")

n.r = g
g.p = n
g.z = d
h.s = d
h.r = n
j.u = d
j.y = n
j.w = n
l.p = n
l.z = h
f.p = n
f.z = d
d.s = h
d.r = n
a.p = n
a.z = d
assert a.p.r.z.r.txt == "n"