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

class B:
    def __init__(self, txt: str):
        self.p: C = None
        self.q: C = None
        self.y: C = None
        self.txt = txt

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

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

n = A("n")
l = B("l")
e = C("e")
f = D("f")
m = C("m")
j = D("j")
i = A("i")
c = A("c")
h = D("h")

n.y = c
l.p = e
l.q = e
l.y = m
e.q = h
e.r = l
f.r = j
f.q = j
m.q = h
m.r = l
j.r = h
j.q = h
i.y = c
c.y = i
h.r = j
h.q = f
assert j.r.r.q.q.r.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.p: C = None
        self.q: C = None
        self.y: C = None
        self.txt = txt

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

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

n = A("n")
l = B("l")
e = C("e")
f = D("f")
m = C("m")
j = D("j")
i = A("i")
c = A("c")
h = D("h")

n.y = c
l.p = e
l.q = e
l.y = m
e.q = h
e.r = l
f.r = j
f.q = j
m.q = h
m.r = l
j.r = h
j.q = h
i.y = c
c.y = i
h.r = j
h.q = f
assert j.r.r.q.q.r.r.r.r.r.txt == "j"