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

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

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

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

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

l.s = f
n.q = h
f.s = l
f.t = n
f.q = c
f.p = c
c.z = a
c.s = n
g.q = l
j.q = l
h.s = f
d.q = l
a.z = c
a.s = j
assert d.q.s.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

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

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

l.s = f
n.q = h
f.s = l
f.t = n
f.q = c
f.p = c
c.z = a
c.s = n
g.q = l
j.q = l
h.s = f
d.q = l
a.z = c
a.s = j
assert d.q.s.p.s.txt == "n"