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

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

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

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

i = A("i")
d = B("d")
m = C("m")
g = D("g")
n = D("n")
h = C("h")

i.q = d
i.p = d
i.r = n
d.t = n
d.u = n
d.w = n
d.p = g
m.u = i
g.z = i
n.z = i
h.u = i
assert h.u.q.p.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.r: D = None
        self.p: B = None
        self.txt = txt

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

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

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

i = A("i")
d = B("d")
m = C("m")
g = D("g")
n = D("n")
h = C("h")

i.q = d
i.p = d
i.r = n
d.t = n
d.u = n
d.w = n
d.p = g
m.u = i
g.z = i
n.z = i
h.u = i
assert h.u.q.p.z.r.txt == "n"