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

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

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

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

m = A("m")
d = B("d")
b = C("b")
f = D("f")
h = D("h")
j = B("j")
i = B("i")
n = A("n")

m.q = h
m.r = b
d.v = h
d.z = h
b.p = d
f.x = n
f.w = h
h.x = m
h.w = f
j.v = f
j.z = h
i.v = f
i.z = h
n.q = h
n.r = b
assert m.q.x.q.x.r.p.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.r: C = None
        self.txt = txt

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

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

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

m = A("m")
d = B("d")
b = C("b")
f = D("f")
h = D("h")
j = B("j")
i = B("i")
n = A("n")

m.q = h
m.r = b
d.v = h
d.z = h
b.p = d
f.x = n
f.w = h
h.x = m
h.w = f
j.v = f
j.z = h
i.v = f
i.z = h
n.q = h
n.r = b
assert m.q.x.q.x.r.p.z.txt == "h"