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

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

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

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

i = A("i")
f = B("f")
b = C("b")
d = D("d")
e = D("e")
m = A("m")
n = A("n")
k = C("k")
g = A("g")

i.q = n
i.w = k
i.u = d
i.p = d
f.w = g
b.o = f
b.t = m
d.r = f
d.z = f
d.x = e
e.r = f
e.z = f
e.x = d
m.q = n
m.w = b
m.u = e
m.p = d
n.q = i
n.w = b
n.u = d
n.p = d
k.o = f
k.t = m
g.q = m
g.w = b
g.u = d
g.p = d
assert n.q.q.w.t.q.u.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.w: C = None
        self.u: D = None
        self.p: D = None
        self.txt = txt

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

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

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

i = A("i")
f = B("f")
b = C("b")
d = D("d")
e = D("e")
m = A("m")
n = A("n")
k = C("k")
g = A("g")

i.q = n
i.w = k
i.u = d
i.p = d
f.w = g
b.o = f
b.t = m
d.r = f
d.z = f
d.x = e
e.r = f
e.z = f
e.x = d
m.q = n
m.w = b
m.u = e
m.p = d
n.q = i
n.w = b
n.u = d
n.p = d
k.o = f
k.t = m
g.q = m
g.w = b
g.u = d
g.p = d
assert n.q.q.w.t.q.u.txt == "d"