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

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

l = A("l")
c = B("c")
d = A("d")
i = B("i")
m = B("m")
n = B("n")
g = B("g")
k = A("k")
h = A("h")
j = B("j")

l.s = d
l.t = m
c.q = n
c.r = g
d.s = l
d.t = j
i.q = m
i.r = j
m.q = c
m.r = i
n.q = m
n.r = i
g.q = n
g.r = m
k.s = l
k.t = i
h.s = l
h.t = m
j.q = m
j.r = c
assert j.r.r.r.r.q.r.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.t: B = None
        self.txt = txt

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

l = A("l")
c = B("c")
d = A("d")
i = B("i")
m = B("m")
n = B("n")
g = B("g")
k = A("k")
h = A("h")
j = B("j")

l.s = d
l.t = m
c.q = n
c.r = g
d.s = l
d.t = j
i.q = m
i.r = j
m.q = c
m.r = i
n.q = m
n.r = i
g.q = n
g.r = m
k.s = l
k.t = i
h.s = l
h.t = m
j.q = m
j.r = c
assert j.r.r.r.r.q.r.q.q.q.q.txt == "m"