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

class B:
    def __init__(self, txt: str):
        self.p: C = None
        self.w: D = None
        self.z: D = None
        self.q: 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.z: A = None
        self.o: A = None
        self.t: B = None
        self.txt = txt

n = A("n")
g = B("g")
m = C("m")
l = D("l")
b = A("b")
k = A("k")
d = C("d")

n.p = m
n.z = l
n.r = l
g.p = d
g.w = l
g.z = l
g.q = l
m.r = d
l.z = b
l.o = n
l.t = g
b.p = m
b.z = l
b.r = l
k.p = d
k.z = l
k.r = l
d.r = m
assert k.p.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.z: D = None
        self.r: D = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.p: C = None
        self.w: D = None
        self.z: D = None
        self.q: 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.z: A = None
        self.o: A = None
        self.t: B = None
        self.txt = txt

n = A("n")
g = B("g")
m = C("m")
l = D("l")
b = A("b")
k = A("k")
d = C("d")

n.p = m
n.z = l
n.r = l
g.p = d
g.w = l
g.z = l
g.q = l
m.r = d
l.z = b
l.o = n
l.t = g
b.p = m
b.z = l
b.r = l
k.p = d
k.z = l
k.r = l
d.r = m
assert k.p.r.r.r.r.txt == "d"