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

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

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

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

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

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

d.s = n
d.y = j
n.w = k
g.q = h
g.r = h
g.y = j
h.r = j
j.q = e
j.r = e
j.y = g
k.s = n
k.y = g
e.r = g
i.s = n
i.y = j
assert e.r.q.r.y.y.y.q.txt == "h"