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

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

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

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

a = A("a")
b = B("b")
d = C("d")
e = D("e")
j = C("j")
g = D("g")
f = D("f")
l = B("l")
n = B("n")
m = A("m")

a.s = e
b.p = n
b.q = f
d.y = j
d.q = l
e.s = m
e.x = m
e.p = a
j.y = d
j.q = b
g.s = a
g.x = a
g.p = m
f.s = a
f.p = a
f.x = m
l.p = b
l.q = e
n.p = l
n.q = g
m.s = e
assert l.q.p.s.p.s.p.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.txt = txt

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

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

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

a = A("a")
b = B("b")
d = C("d")
e = D("e")
j = C("j")
g = D("g")
f = D("f")
l = B("l")
n = B("n")
m = A("m")

a.s = e
b.p = n
b.q = f
d.y = j
d.q = l
e.s = m
e.x = m
e.p = a
j.y = d
j.q = b
g.s = a
g.x = a
g.p = m
f.s = a
f.p = a
f.x = m
l.p = b
l.q = e
n.p = l
n.q = g
m.s = e
assert l.q.p.s.p.s.p.s.s.txt == "m"