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

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

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

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

h = A("h")
a = B("a")
j = C("j")
b = D("b")
d = A("d")
f = D("f")
g = B("g")
m = C("m")

h.w = a
h.t = b
a.q = f
j.u = g
j.s = m
j.v = m
b.r = j
b.z = f
d.w = a
d.t = b
f.r = j
f.z = b
g.q = f
m.u = g
m.s = j
m.v = j
assert d.w.q.r.u.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.t: D = None
        self.txt = txt

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

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

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

h = A("h")
a = B("a")
j = C("j")
b = D("b")
d = A("d")
f = D("f")
g = B("g")
m = C("m")

h.w = a
h.t = b
a.q = f
j.u = g
j.s = m
j.v = m
b.r = j
b.z = f
d.w = a
d.t = b
f.r = j
f.z = b
g.q = f
m.u = g
m.s = j
m.v = j
assert d.w.q.r.u.txt == "g"