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

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

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

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

d = A("d")
c = B("c")
b = C("b")
h = D("h")
k = B("k")
g = D("g")
i = C("i")
f = B("f")
a = A("a")

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

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

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

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

d = A("d")
c = B("c")
b = C("b")
h = D("h")
k = B("k")
g = D("g")
i = C("i")
f = B("f")
a = A("a")

d.q = f
d.z = b
c.x = i
c.r = b
b.p = c
b.x = a
b.w = g
h.w = f
h.y = g
k.x = b
k.r = b
g.w = c
g.y = h
i.p = f
i.x = a
i.w = g
f.x = i
f.r = i
a.q = c
a.z = i
assert a.q.r.w.w.r.x.z.p.txt == "f"