class A:
    def __init__(self, txt: str):
        self.w: B = 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.q: D = None
        self.w: C = None
        self.t: D = None
        self.txt = txt

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

l = A("l")
m = B("m")
g = C("g")
a = D("a")
d = A("d")
k = B("k")
i = D("i")
j = C("j")
f = A("f")
e = D("e")

l.w = m
m.q = e
g.q = i
g.t = i
g.w = j
a.q = j
a.r = d
d.w = k
k.q = i
i.q = j
i.r = l
j.q = e
j.t = e
j.w = g
f.w = k
e.q = g
e.r = d
assert m.q.q.w.w.t.q.t.r.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = 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.q: D = None
        self.w: C = None
        self.t: D = None
        self.txt = txt

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

l = A("l")
m = B("m")
g = C("g")
a = D("a")
d = A("d")
k = B("k")
i = D("i")
j = C("j")
f = A("f")
e = D("e")

l.w = m
m.q = e
g.q = i
g.t = i
g.w = j
a.q = j
a.r = d
d.w = k
k.q = i
i.q = j
i.r = l
j.q = e
j.t = e
j.w = g
f.w = k
e.q = g
e.r = d
assert m.q.q.w.w.t.q.t.r.w.txt == "k"