class A:
    def __init__(self, txt: str):
        self.q: 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.p: B = None
        self.u: A = None
        self.r: B = None
        self.s: A = None
        self.txt = txt

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

e = A("e")
g = B("g")
d = C("d")
n = D("n")
c = C("c")
l = C("l")
m = B("m")
f = B("f")

e.q = f
g.p = n
d.p = m
d.r = m
d.u = e
d.s = e
n.u = f
c.p = g
c.u = e
c.s = e
c.r = f
l.p = m
l.r = m
l.u = e
l.s = e
m.p = n
f.p = n
assert f.p.u.p.u.p.txt == "
class A:
    def __init__(self, txt: str):
        self.q: 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.p: B = None
        self.u: A = None
        self.r: B = None
        self.s: A = None
        self.txt = txt

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

e = A("e")
g = B("g")
d = C("d")
n = D("n")
c = C("c")
l = C("l")
m = B("m")
f = B("f")

e.q = f
g.p = n
d.p = m
d.r = m
d.u = e
d.s = e
n.u = f
c.p = g
c.u = e
c.s = e
c.r = f
l.p = m
l.r = m
l.u = e
l.s = e
m.p = n
f.p = n
assert f.p.u.p.u.p.txt == "n"