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

class B:
    def __init__(self, txt: str):
        self.x: A = None
        self.y: C = None
        self.r: B = None
        self.t: D = None
        self.txt = txt

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

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

e = A("e")
m = B("m")
k = C("k")
d = D("d")
g = C("g")
j = D("j")
h = B("h")
n = B("n")
a = D("a")

e.t = g
m.x = e
m.y = k
m.r = n
m.t = d
k.q = e
d.x = g
d.s = k
d.w = e
g.q = e
j.x = k
j.s = g
j.w = e
h.x = e
h.y = k
h.r = n
h.t = a
n.x = e
n.y = g
n.r = h
n.t = a
a.x = g
a.s = g
a.w = e
assert k.q.t.q.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.x: A = None
        self.y: C = None
        self.r: B = None
        self.t: D = None
        self.txt = txt

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

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

e = A("e")
m = B("m")
k = C("k")
d = D("d")
g = C("g")
j = D("j")
h = B("h")
n = B("n")
a = D("a")

e.t = g
m.x = e
m.y = k
m.r = n
m.t = d
k.q = e
d.x = g
d.s = k
d.w = e
g.q = e
j.x = k
j.s = g
j.w = e
h.x = e
h.y = k
h.r = n
h.t = a
n.x = e
n.y = g
n.r = h
n.t = a
a.x = g
a.s = g
a.w = e
assert k.q.t.q.t.txt == "g"