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

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

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

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

i = A("i")
m = B("m")
c = C("c")
f = D("f")
d = B("d")
a = D("a")
n = C("n")
b = B("b")

i.q = n
i.p = d
m.z = f
m.y = f
c.u = n
f.s = d
f.z = a
f.w = m
d.z = f
d.y = a
a.s = d
a.z = f
a.w = b
n.u = c
b.z = a
b.y = f
assert b.z.s.z.w.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.p: B = None
        self.txt = txt

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

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

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

i = A("i")
m = B("m")
c = C("c")
f = D("f")
d = B("d")
a = D("a")
n = C("n")
b = B("b")

i.q = n
i.p = d
m.z = f
m.y = f
c.u = n
f.s = d
f.z = a
f.w = m
d.z = f
d.y = a
a.s = d
a.z = f
a.w = b
n.u = c
b.z = a
b.y = f
assert b.z.s.z.w.z.txt == "f"