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

class B:
    def __init__(self, txt: str):
        self.q: B = None
        self.r: B = None
        self.y: D = None
        self.w: C = None
        self.txt = txt

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

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

k = A("k")
f = B("f")
g = C("g")
n = D("n")
a = B("a")
i = A("i")
l = B("l")
d = D("d")
c = B("c")

k.p = a
f.q = c
f.r = c
f.y = n
f.w = g
g.q = l
n.z = l
n.q = l
a.q = f
a.r = l
a.y = n
a.w = g
i.p = f
l.q = c
l.r = a
l.y = n
l.w = g
d.z = c
d.q = f
c.q = f
c.r = f
c.y = d
c.w = g
assert l.q.q.y.z.w.q.w.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.q: B = None
        self.r: B = None
        self.y: D = None
        self.w: C = None
        self.txt = txt

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

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

k = A("k")
f = B("f")
g = C("g")
n = D("n")
a = B("a")
i = A("i")
l = B("l")
d = D("d")
c = B("c")

k.p = a
f.q = c
f.r = c
f.y = n
f.w = g
g.q = l
n.z = l
n.q = l
a.q = f
a.r = l
a.y = n
a.w = g
i.p = f
l.q = c
l.r = a
l.y = n
l.w = g
d.z = c
d.q = f
c.q = f
c.r = f
c.y = d
c.w = g
assert l.q.q.y.z.w.q.w.q.txt == "l"