Petya once wrote a sad love song and shared it to Vasya. The song is a string consisting of lowercase English letters. Vasya made up $q$ questions about this song. Each question is about a subsegment of the song starting from the $l$-th letter to the $r$-th letter. Vasya considers a substring made up from characters on this segment and repeats each letter in the subsegment $k$ times, where $k$ is the index of the corresponding letter in the alphabet. For example, if the question is about the substring "abbcb", then Vasya repeats letter 'a' once, each of the letters 'b' twice, letter 'c" three times, so that the resulting string is "abbbbcccbb", its length is $10$. Vasya is interested about the length of the resulting string.

Help Petya find the length of each string obtained by Vasya.


-----Input-----

The first line contains two integers $n$ and $q$ ($1\leq n\leq 100000$, $1\leq q \leq 100000$) — the length of the song and the number of questions.

The second line contains one string $s$ — the song, consisting of $n$ lowercase letters of English letters.

Vasya's questions are contained in the next $q$ lines. Each line contains two integers $l$ and $r$ ($1 \leq l \leq r \leq n$) — the bounds of the question.


-----Output-----

Print $q$ lines: for each question print the length of the string obtained by Vasya.


-----Examples-----

Input
7 3
abacaba
1 3
2 5
1 7
Output
4
7
11
Input
7 4
abbabaa
1 3
5 7
6 6
2 4
Output
5
4
1
5
Input
13 7
sonoshikumiwo
1 5
2 10
7 7
1 13
4 8
2 5
3 9
Output
82
125
9
191
62
63
97


-----Note-----

In the first example Vasya is interested in three questions. In the first question Vasya considers the substring "aba", that transforms to "abba", so the answer is equal to $4$. In the second question Vasya considers "baca", that transforms to "bbaccca", so the answer is $7$. In the third question Vasya considers the string "abacaba",that transforms to "abbacccabba" of length $11$.

Difficulty: EASY
Tags: String algorithms

Dynamic programming

Implementation
Skill types: Dynamic programming

Starter code:

Solutions:
(n, q) = map(int, input().split())
s = input()
prd = [0]
alp = 'abcdefghijklmnopqrstuvwxyz'
alp_m = {}
for i in range(len(alp)):
	alp_m[alp[i]] = i + 1
for i in range(1, len(s) + 1):
	prd.append(prd[i - 1] + alp_m[s[i - 1]])
for i in range(q):
	(l, r) = map(int, input().split())
	print(prd[r] - prd[l - 1])


d = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
(n, q) = map(int, input().split())
s = str(input())
arr = []
arr.append(d[s[0]])
for i in range(1, n):
	x = d[s[i]]
	y = arr[-1]
	arr.append(x + y)
for i in range(q):
	(a, b) = map(int, input().split())
	if a == 1:
		if b == n:
			print(arr[-1])
		else:
			print(arr[b - 1])
	else:
		print(arr[b - 1] - arr[a - 2])


try:
	import sys
	import math
	import collections
	M = 10 ** 9 + 7

	def fillPrefixSum(arr, n, prefixSum):
		prefixSum[0] = arr[0]
		for i in range(1, n):
			prefixSum[i] = prefixSum[i - 1] + arr[i]

	def solve():
		(length, q) = map(int, input().split())
		string = input()
		string = string.replace('\r', '')
		d = {}
		count = 1
		for i in range(97, 123):
			d[chr(i)] = count
			count += 1
		arr = []
		for i in string:
			arr.append(d.get(i))
		prefixSum = [0 for i in range(length)]
		fillPrefixSum(arr, length, prefixSum)
		for i in range(q):
			(a, b) = map(int, input().split())
			total = prefixSum[b - 1] - prefixSum[a - 1] + arr[a - 1]
			print(total)
		return
	count1 = 1
	solve()
except EOFError:
	print('')


(n, q) = [int(x) for x in input().split()]
s = input()
a = [0]
for i in s:
	a.append(a[-1] + (ord(i) - 96))
while q:
	(l, r) = [int(x) for x in input().split()]
	print(a[r] - a[l - 1])
	q -= 1


(n, q) = map(int, input().split())
s = input()
li = [0]
for i in s:
	li.append(li[-1] + ord(i) - 96)
for j in range(q):
	(l, r) = map(int, input().split())
	print(li[r] - li[l - 1])


(n, q) = map(int, input().split())
s = input()
arr = [0] * (n + 1)
j = 1
for i in s:
	if j == 1:
		arr[j] = ord(i) - 96
	else:
		arr[j] = ord(i) - 96 + arr[j - 1]
	j += 1
for i in range(q):
	(l, r) = map(int, input().split())
	print(arr[r] - arr[l - 1])


(n, s, *a) = open(0)
b = [0]
for x in s:
	b += (b[-1] + ord(x) - 96,)
for s in a:
	(l, r) = map(int, s.split())
	print(b[r] - b[l - 1])


(n, s, *a) = open(0)
ar = [0]
for x in s:
	ar.append(ar[-1] + ord(x) - 96)
for s in a:
	(a2, b2) = map(int, s.split())
	print(ar[b2] - ar[a2 - 1])


from collections import Counter, defaultdict, deque
import math
from heapq import *
import sys
input = sys.stdin.readline

def solve():
	(n, q) = [int(x) for x in input().split()]
	t = [ord(x) - ord('a') + 1 for x in input().strip()]
	s = [0]
	for i in t:
		s.append(s[-1] + i)
	for i in range(q):
		(l, r) = [int(x) for x in input().split()]
		print(s[r] - s[l - 1])
tt = 1
for test in range(tt):
	solve()


from sys import path_hooks, stdin, stdout
from collections import Counter, deque
import math
from copy import deepcopy
import random
import heapq
import sys
sys.setrecursionlimit(10 ** 5)

def mapinput():
	return map(int, stdin.readline().split())

def strinput():
	return stdin.readline().strip()

def listinput():
	return list(map(int, stdin.readline().split()))

def intinput():
	return int(stdin.readline().strip())

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = False
	prime[1] = False
	ans = []
	for p in range(n + 1):
		if prime[p]:
			ans.append(p)
	return ans
coprime1 = {6: 100003, 5: 10007, 4: 1009, 3: 101, 2: 11, 1: 2, 7: 1000003, 8: 10000019, 9: 100000007}
coprime2 = {8: 10000169, 9: 100000049, 7: 1000033, 6: 100019, 5: 10009, 4: 1013, 3: 103, 2: 13, 1: 3}

def writ(ss):
	stdout.write(str(ss) + '\n')
mod = 10 ** 9 + 7

def sumn(n):
	return n * (n + 1) // 2
for test in range(1):

	def solve():
		(n, q) = mapinput()
		s = strinput()
		coun = 0
		lr = {}
		score = {}
		for i in 'qwertyuiopasdfghjklzxcvbnm':
			score[i] = ord(i) - 96
		for i in range(n):
			lr[i] = coun
			coun += score[s[i]]
		lr[n] = coun
		for i in range(q):
			(l, r) = mapinput()
			print(lr[r] - lr[l - 1])
	solve()


l = list(map(int, input().rstrip().split()))
n = l[0]
t = l[1]
s = str(input())
lis = []
sum = 0
for d in range(n):
	sum += ord(s[d]) - 96
	lis.append(sum)
for h in range(t):
	l1 = list(map(int, input().rstrip().split()))
	a = l1[0]
	b = l1[1]
	if a > 1:
		print(lis[b - 1] - lis[a - 2])
	else:
		print(lis[b - 1])


import sys
import string
parse_input = lambda : sys.stdin.readline().rstrip('\r\n')

def calc_prefix(song):
	prefix_sum = 0
	prefix = []
	for i in range(len(song)):
		prefix_sum += string.ascii_lowercase.index(song[i]) + 1
		prefix.append(prefix_sum)
	prefix.insert(0, 0)
	return prefix

def func(prefix, l, r):
	total = prefix[r] - prefix[l - 1]
	return total

def main():
	(n, q) = [int(i) for i in parse_input().split()]
	song = parse_input()
	prefix = calc_prefix(song)
	for j in range(q):
		(l, r) = [int(i) for i in parse_input().split()]
		print(func(prefix, l, r))
main()


import collections
(n, q) = tuple(map(int, input().split(' ')))
s = input()
problems = [tuple(map(int, input().split(' '))) for problem in range(q)]
dictr = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
prefics_summs = [0]
for i in range(len(s)):
	prefics_summs.append(prefics_summs[-1] + dictr[s[i]])
for (l, r) in problems:
	print(prefics_summs[r] - prefics_summs[l - 1])


(l, n) = map(int, input().split())
s = input()
list1 = [0]
for i in range(l):
	list1.append(ord(s[i]) - 96 + list1[-1])
for i in range(n):
	(l, r) = map(int, input().split())
	print(list1[r] - list1[l - 1])


(_, n) = map(int, input().split())
s = input()
x = [0]
for w in s:
	x.append(x[-1] + ord(w) - 96)
for _ in range(0, n):
	(b, e) = map(int, input().split())
	print(x[e] - x[b - 1])


from collections import Counter
song = ''
preSum = []

def solve(l, r):
	response = 0
	if l - 2 < 0:
		c = preSum[r - 1]
	else:
		c = preSum[r - 1] - preSum[l - 2]
	return c
(_, t) = list(map(int, input().split()))
song = input()
ctr = 0
for val in song:
	ctr += ord(val) - ord('a') + 1
	preSum.append(ctr)
for test in range(1, t + 1):
	(l, r) = list(map(int, input().split()))
	print(f'{solve(l, r)}')


(a, b) = input().split()
a = int(a)
b = int(b)
s = input()
temp = [0]
ans = []
for i in s:
	temp.append(temp[-1] + (ord(i) - 96))
for i in range(b):
	(x1, x2) = input().split()
	x1 = int(x1)
	x2 = int(x2)
	ans.append(temp[x2] - temp[x1 - 1])
for j in ans:
	print(j)


(n, q) = map(int, input().split())
song = input()
ans = [0]
for ch in song:
	ans.append(ans[-1] + ord(ch) - 96)
for i in range(q):
	(l, r) = map(int, input().split())
	print(ans[r] - ans[l - 1])


(n, q) = map(int, input().split())
s = input()
ps = [0 for i in range(n + 1)]
for i in range(n):
	ps[i + 1] += ps[i] + ord(s[i]) % 96
for _ in range(q):
	(l, r) = map(int, input().split())
	print(ps[r] - ps[l - 1])


def fillPrefixSum(arr, n, prefixSum):
	prefixSum[0] = arr[0]
	for i in range(1, n):
		prefixSum[i] = prefixSum[i - 1] + arr[i]
	return prefixSum
(n, q) = map(int, input().split(' '))
s = list(input())
p = [0]
pre = [0 for i in range(n + 1)]
for k in s:
	p.append(ord(k) - 96)
prefix = fillPrefixSum(p, n + 1, pre)
for i in range(q):
	(l, r) = map(int, input().split(' '))
	print(prefix[r] - prefix[l - 1])


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
(n, q) = mp()
s = inp()
md = {}
for i in range(26):
	md[S1[i]] = i + 1
ml = l1d(n + 1)
for i in range(1, n + 1):
	ml[i] = ml[i - 1] + md[s[i - 1]]
for i in range(q):
	(x, y) = mp()
	print(ml[y] - ml[x - 1])


[n, q] = list(map(int, input().split()))
s = input()
dem = [[0 for k in range(len(s) + 4)] for k in range(30)]
for i in range(26):
	c = chr(ord('a') + i)
	for j in range(len(s)):
		dem[i][j + 1] = dem[i][j] + (1 if s[j] == c else 0)
for _ in range(q):
	[l, r] = list(map(int, input().split()))
	ans = 0
	for i in range(26):
		ans += (i + 1) * (dem[i][r] - dem[i][l - 1])
	print(ans)


from collections import defaultdict
import sys

def getIdx(i):
	return ord(i) - ord('a') + 1

def Getvalue(l, r, prefix):
	return prefix[r] - prefix[l - 1]
(n, q) = list(map(int, input().strip().split()))
s = input().strip()
prefix = [0 for _ in range(len(s) + 1)]
for i in range(len(s)):
	prefix[i + 1] = prefix[i] + getIdx(s[i])
for _ in range(q):
	(l, r) = list(map(int, input().strip().split()))
	print(Getvalue(l, r, prefix))


from collections import defaultdict

def findAns(s):
	A = defaultdict(lambda : 0)
	alp = 'abcdefghijklmnopqrstuvwxyz'
	for i in range(len(alp)):
		A[alp[i]] = i + 1
	arr = [0]
	res = 0
	for i in range(len(s)):
		res += A[s[i]]
		arr.append(res)
	return arr
(n, q) = [int(x) for x in input().split(' ')]
s = str(input())
Q = []
for i in range(q):
	(l, r) = [int(x) for x in input().split(' ')]
	Q.append([l, r])
lst = findAns(s)
for (l, r) in Q:
	print(lst[r] - lst[l - 1])


(n, q) = map(int, input().split())
s = input()
lan = []
ls = []
ctr = 0
for indx in range(n):
	ctr += ord(s[indx]) - 96
	ls.append(ctr)
for x in range(q):
	(l, r) = map(int, input().split())
	if l == 1:
		lan.append(ls[r - 1])
	else:
		lan.append(ls[r - 1] - ls[l - 2])
print(*lan, sep='\n')


from typing import List, Tuple

def dict_scores(txt: str) -> Tuple[int]:
	nums_tree = [0]
	a_base = 96
	n_sum = 0
	for ch in txt:
		n_sum += ord(ch) - a_base
		nums_tree.append(n_sum)
	return tuple(nums_tree)
(n_in, q_in) = map(int, input().split())
song = input()
answ_list = []
song_score = dict_scores(song)
for _ in range(q_in):
	(start, end) = map(int, input().split())
	answ_list.append(song_score[end] - song_score[start - 1])
print(*answ_list, sep='\n')


(n, q) = map(int, input().split())
s = input()
d1 = dict()
d2 = dict()
ans = ''
t = 0
for i in range(n):
	d2[i] = t
	val = ord(s[i]) - ord('a') + 1
	t += val
	d1[i] = t
while q:
	q -= 1
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	print(d1[y] - d2[x])


import sys
(songlen, testcases) = map(int, sys.stdin.readline().split())
string = sys.stdin.readline().strip()
psa = [0]
for i in range(1, songlen + 1):
	psa.append(psa[i - 1] + ord(string[i - 1]) - 96)
for _ in range(testcases):
	(l, r) = map(int, sys.stdin.readline().split())
	print(psa[r] - psa[l - 1])


from __future__ import print_function
from collections import *
from sys import stdin
from bisect import *
from heapq import *
from math import log2
from math import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
rr = lambda x: reversed(range(x))
mod = int(1000000000.0) + 7
inf = float('inf')
(n, q) = gil()
mat = [[0 for _ in range(n + 1)] for _ in range(26)]
i = 0
for v in gcl():
	r = ord(v) - 97
	mat[r][i] += 1
	i += 1
for i in range(26):
	for j in range(1, n):
		mat[i][j] += mat[i][j - 1]

def solve(l, r):
	ans = 0
	for i in range(26):
		ans += (mat[i][r] - mat[i][l - 1]) * (i + 1)
	return ans
for _ in range(q):
	(l, r) = gil()
	print(solve(l - 1, r - 1))


def create_seg_tree(seg_arr, normy_arr, index, i, j):
	if i == j:
		seg_arr[index] = ord(normy_arr[i]) - 96
		return
	else:
		mid = (i + j) // 2
		create_seg_tree(seg_arr, normy_arr, 2 * index, i, mid)
		create_seg_tree(seg_arr, normy_arr, 2 * index + 1, mid + 1, j)
		left = seg_arr[2 * index]
		right = seg_arr[2 * index + 1]
		seg_arr[index] = left + right
	return seg_arr

def query(seg_arr, index, i, j, qi, qj):
	if qj < i or qi > j:
		return 0
	if qi <= i and qj >= j:
		return seg_arr[index]
	mid = (i + j) // 2
	left = query(seg_arr, 2 * index, i, mid, qi, qj)
	right = query(seg_arr, 2 * index + 1, mid + 1, j, qi, qj)
	return left + right
(n, q) = map(int, input().split())
s = list(map(str, input()))
infinity = float('inf')
segment = list((infinity for item in range(4 * n + 1)))
create_seg_tree(segment, s, 1, 0, n - 1)
for i in range(q):
	(x, y) = map(int, input().split())
	print(query(segment, 1, 0, n - 1, x - 1, y - 1))


(n, k) = [int(x) for x in input().split()]
s = input()
l = [0]
for i in range(n):
	score = ord(s[i]) - 96
	l.append(l[-1] + score)
for _ in range(k):
	(a, b) = [int(x) for x in input().split()]
	print(l[b] - l[a - 1])


(n, q) = list(map(int, input().split()))
s = list(input())
result = {chr(i + 96): i for i in range(1, 27)}
r = []
maxi = 0
suum = 0
for i in range(len(s)):
	suum += result[s[i]]
	if suum > maxi:
		maxi = suum
		r.append(maxi)
for i in range(q):
	(l, h) = map(int, input().split())
	if l == 1:
		print(r[h - 1])
	else:
		print(r[h - 1] - r[l - 2])


(n, q) = [int(x) for x in input().split()]
l = input()
s = []
s.append(ord(l[0]) - 96)
for i in range(1, n):
	s.append(s[i - 1] + ord(l[i]) - 96)
while q:
	(a, b) = [int(x) for x in input().split()]
	if a != 1:
		print(s[b - 1] - s[a - 2])
	else:
		print(s[b - 1])
	q -= 1


(n, q) = map(int, input().split())
s = input()
arr = [0]
for x in s:
	arr.append(arr[-1] + (ord(x) - ord('a') + 1))
for x in range(q):
	(a, b) = map(int, input().split())
	print(arr[b] - arr[a - 1])


(n, q) = map(int, input().split())
s = input()
ps = [0] * len(s)
ps[0] = ord(s[0]) - 96
for i in range(1, len(s)):
	ps[i] = ps[i - 1] + ord(s[i]) - 96
for _ in range(q):
	(l, r) = map(int, input().split())
	if l == 1:
		print(ps[r - 1])
	else:
		print(ps[r - 1] - ps[l - 2])


(n, q) = map(int, input().split())
s = input()
l = []
t = 0
for i in s:
	t += ord(i) - 96
	l.append(t)
for _ in range(q):
	(a, b) = map(int, input().split())
	summ = l[b - 1] - l[a - 1] + ord(s[a - 1]) - 96
	print(summ)


from sys import path_hooks, stdin, stdout
from collections import Counter, deque
import math
from copy import deepcopy
import random
import heapq
from itertools import permutations, repeat
from time import time
from bisect import bisect_left
from bisect import bisect_right
from re import findall
from fractions import Fraction
from typing import DefaultDict

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = False
	prime[1] = False
	ans = []
	for p in range(n + 1):
		if prime[p]:
			ans.append(p)
	return ans
spprime = [2, 3, 5, 7, 23, 29, 31, 37, 53, 59, 71, 73, 79, 233, 239, 293, 311, 313, 317, 373, 379, 593, 599, 719, 733, 739, 797, 2333, 2339, 2393, 2399, 2939, 3119, 3137, 3733, 3739, 3793, 3797, 5939, 7193, 7331, 7333, 7393, 23333, 23339, 23399, 23993, 29399, 31193, 31379, 37337, 37339, 37397, 59393, 59399, 71933, 73331, 73939, 233993, 239933, 293999, 373379, 373393, 593933, 593993, 719333, 739391, 739393, 739397, 739399, 2339933, 2399333, 2939999, 3733799]
spprimeset = set(spprime)
coprime1 = {6: 100003, 5: 10007, 4: 1009, 3: 101, 2: 11, 1: 2, 7: 1000003, 8: 10000019, 9: 100000007}
coprime2 = {8: 10000169, 9: 100000049, 7: 1000033, 6: 100019, 5: 10009, 4: 1013, 3: 103, 2: 13, 1: 3}

def writ(ss):
	stdout.write(str(ss) + '\n')
mod = 10 ** 9 + 7

def binaryr(arr, point, target):
	low = 0
	high = point
	while low <= high:
		mid = (low + high) // 2
		if arr[mid] == target:
			return mid
		elif arr[mid] < target:
			low = mid + 1
		else:
			high = mid - 1
	return low

def binaryl(arr, point, target):
	low = 0
	high = point
	while low <= high:
		mid = (low + high) // 2
		if arr[mid] == target:
			return mid
		elif arr[mid] < target:
			low = mid + 1
		else:
			high = mid - 1
	return high

def sump(n):
	return n * (n + 1) // 2
(n, q) = map(int, stdin.readline().split())
s = stdin.readline().strip()
score = {}
c = 1
for i in sorted('qwertyuiopasdfghjklzxcvbnm'):
	score[i] = c
	c += 1
lis = {}
for i in 'qwertyuiopasdfghjklzxcvbnm':
	lis[i] = [0] * (n + 1)
for i in range(n):
	for j in lis:
		if j == s[i]:
			lis[j][i + 1] = lis[j][i] + 1
		else:
			lis[j][i + 1] = lis[j][i]

def solve():
	(l, r) = map(int, stdin.readline().split())
	ans = 0
	for i in 'qwertyuiopasdfghjklzxcvbnm':
		coun = lis[i][r] - lis[i][l - 1]
		ans += coun * score[i]
	return ans
for test in range(q):
	print(solve())


import sys
from sys import stdin, stdout
(input, print) = (stdin.readline, stdout.write)
from collections import OrderedDict, defaultdict
from bisect import bisect_left
import math
from math import gcd, sqrt, floor, ceil
from string import ascii_lowercase
(n, q) = [int(x) for x in input().split()]
s = input()
hsh = defaultdict(list)
for c in ascii_lowercase:
	hsh[c] = [0]
	li = hsh[c]
	for i in range(n):
		li.append(li[-1])
		if s[i] == c:
			li[-1] += 1
for Q in range(q):
	(l, r) = [int(x) for x in input().split()]
	res = 0
	i = 1
	for c in ascii_lowercase:
		li = hsh[c]
		res += i * int(li[r] - li[l - 1])
		i += 1
	print(str(res) + '\n')
print('\n')


(num, item) = map(int, input().split(' '))
arr = input()
input_arr = []
for _ in range(item):
	(one, two) = map(int, input().split(' '))
	input_arr.append([one, two])
f = lambda x: ord(x) - 96
arr_num = list(map(f, list(arr)))
p_len = len(arr_num)
pre_arr = [0] * p_len
for i in range(1, p_len):
	pre_arr[i] = pre_arr[i - 1] + arr_num[i]
for (x, y) in input_arr:
	x -= 1
	y -= 1
	res = pre_arr[y] - pre_arr[x] + arr_num[x]
	print(res)


(n, q) = map(int, input().split())
s = input()
l = [0] * (n + 1)
x = ord('a') - 1
for i in range(1, n + 1):
	l[i] += l[i - 1] + ord(s[i - 1]) - x
for i in range(q):
	(x, y) = map(int, input().split())
	print(l[y] - l[x - 1])


import string
alphabet_dict = {letter: i + 1 for (i, letter) in enumerate(string.ascii_lowercase)}
(n, q) = map(int, input().split())
song = str(input())
ans = []
ans_ = [0]
for l in song:
	ans_.append(ans_[-1] + alphabet_dict[l])
for i in range(q):
	(l, r) = map(int, input().split())
	ans.append(ans_[r] - ans_[l - 1])
for a in ans:
	print(a)


(n, q) = map(int, input().split())
s = input()
pre = [0] * len(s)
for i in range(1, len(s)):
	pre[i] = pre[i - 1] + (ord(s[i - 1]) - 96)
post = [0] * len(s)
for i in range(len(s) - 2, -1, -1):
	post[i] = post[i + 1] + (ord(s[i + 1]) - 96)
total_sum = post[0] + ord(s[0]) - 96
for i in range(q):
	(l, r) = map(int, input().split())
	print(total_sum - pre[l - 1] - post[r - 1])


(n, q) = map(int, input().split())
s = input()
sums = [0] * (len(s) + 1)
for i in range(1, len(s) + 1):
	sums[i] = sums[i - 1] + (ord(s[i - 1]) - 96)
for i in range(q):
	(l, r) = map(int, input().split())
	print(sums[r] - sums[l - 1])


(n, q) = map(int, input().split())
p = [0]
for i in input():
	p += [p[-1] + ord(i) - 96]
for _ in range(q):
	(a, b) = map(int, input().split())
	print(p[b] - p[a - 1])


from sys import stdin
input = stdin.readline
from math import ceil, gcd
(n, q) = map(int, input().split())
s = input().strip()
f = [0]
for i in range(n):
	f.append(f[-1] + (ord(s[i]) - 96))
for i in range(q):
	(l, r) = map(int, input().split())
	print(f[r] - f[l - 1])


(n, q) = map(int, input().split())
s = input()
cdic = []
clis = [0]
temp = 0
for i in s:
	v = temp + ord(i) - 96
	clis.append(v)
	temp = v
for __ in range(q):
	(l, r) = map(int, input().split())
	print(clis[r] - clis[l - 1])


(n, q) = tuple([int(x) for x in input().split()])
string = input()
arr = []
cum_sum = [0] * (n + 1)
for a in range(1, n + 1):
	cum_sum[a] = cum_sum[a - 1] + ord(string[a - 1]) - 96
for b in range(q):
	(l, r) = tuple([int(x) for x in input().split()])
	arr.append(cum_sum[r] - cum_sum[l - 1])
for element in arr:
	print(element)


from timeit import timeit
import os, sys
from datetime import datetime
from math import floor, ceil, sqrt, gcd, factorial
from collections import Counter, defaultdict
import bisect

def readint():
	return int(sys.stdin.readline())

def readstr():
	return sys.stdin.readline()

def readlst():
	return list(map(int, sys.stdin.readline().strip().split()))

def readmul():
	return map(int, sys.stdin.readline().strip().split())

def mulfloat():
	return map(float, sys.stdin.readline().strip().split())

def flush():
	return sys.stdout.flush()

def power_two(x):
	return 1 << x

def lcm(a, b):
	return a * b // gcd(a, b)
INF = float('inf')
mod = int(1000000000.0) + 7

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
			return n - leftGreater

def two_pointer(n, val, *arr):
	(l, r, cnt) = (0, n - 1, 0)
	while l < r:
		if arr[l] + arr[r] > val:
			r -= 1
		else:
			cnt += r - l
			l += 1
	return cnt

def lower(arr, n, val):
	(l, r) = (-1, n)
	while r > l + 1:
		m = int(l + r >> 1)
		if arr[m] < val:
			l = m
		else:
			r = m
	return r

def upper(arr, n, val):
	(l, r) = (-1, n)
	while r > l + 1:
		m = int(l + r >> 1)
		if arr[m] <= val:
			l = m
		else:
			r = m
	return l

def binpow(a, n, mod):
	while n:
		if n & 1:
			res = res * a % mod
			n -= 1
		a = a * a % mod
		n = n >> 1
	return res

def check(s):
	cnt = 0
	for i in s:
		if i == '(':
			cnt += 1
		elif i == ')':
			cnt -= 1
	return cnt == 0

def omkar():
	(n, q) = readmul()
	s = input()
	hsh = [0] * (n + 1)
	for i in range(0, n):
		hsh[i + 1] = ord(s[i]) - ord('a') + 1
	for i in range(1, n + 1):
		hsh[i] += hsh[i - 1]
	for i in range(q):
		(l, r) = readmul()
		print(hsh[r] - hsh[l - 1])
	return

def main():
	test = 1
	while test:
		omkar()
		test -= 1
main()


import math, bisect
(n, q) = map(int, input().split())
store = [[0 for i in range(26)] for j in range(n + 1)]
a = input()
for i in range(n):
	store[i + 1] = list(store[i])
	store[i + 1][ord(a[i]) - ord('a')] += 1
for t in range(q):
	(l, r) = map(int, input().split())
	ans = 0
	for i in range(26):
		ans += (store[r][i] - store[l - 1][i]) * (i + 1)
	print(ans)


import sys
import math
import random
from queue import PriorityQueue as PQ
from bisect import bisect_left as BSL
from bisect import bisect_right as BSR
from collections import OrderedDict as OD
from collections import Counter
from itertools import permutations
from decimal import Decimal as BIGFLOAT
from copy import deepcopy
mod = 1000000007
MOD = mod
sys.setrecursionlimit(1000000)
try:
	sys.stdin = open('actext.txt', 'r')
	OPENFILE = 1
except:
	pass

def get_ints():
	return map(int, input().split())

def palindrome(s):
	mid = len(s) // 2
	for i in range(mid):
		if s[i] != s[len(s) - i - 1]:
			return False
	return True

def check(i, n):
	if 0 <= i < n:
		return True
	else:
		return False
(n, q) = get_ints()
s = input()
mp = {}
for (num, i) in enumerate('abcdefghijklmnopqrstuvwxyz'):
	mp[i] = num + 1
arr = []
for i in s:
	arr.append(mp[i])
pre = [0]
for i in arr:
	pre.append(pre[-1] + i)
for qq in range(q):
	(l, r) = get_ints()
	print(pre[r] - pre[l - 1])


(n, q) = map(int, input().split())
s = input()
l = [0]
for i in s:
	l.append(l[-1] + ord(i) - 96)
for i in range(q):
	(v, b) = map(int, input().split())
	print(l[b] - l[v - 1])


from sys import *
input = lambda : stdin.readline()
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)
(n, q) = get_int()
dp = [0] * (n + 1)
s = str(input())
for i in range(1, n + 1):
	dp[i] = dp[i - 1] + ord(s[i - 1]) % 97 + 1
for i in range(q):
	(l, r) = get_int()
	print(dp[r] - dp[l - 1])


(n, q) = list(map(int, input().split()))
s = input()
list_prefix_sums = [0]
for i in range(1, n + 1):
	list_prefix_sums.append(list_prefix_sums[i - 1] + (ord(s[i - 1]) - ord('a') + 1))
for i in range(q):
	(l, r) = list(map(int, input().split()))
	print(list_prefix_sums[r] - list_prefix_sums[l - 1])


arr = list(map(int, input().split(' ')))
n = arr[0]
q = arr[1]
s = input()
csum = [[0] * 26 for i in range(n)]
csum[0][ord(s[0]) - ord('a')] = 1
for i in range(1, n):
	for j in range(26):
		if j == ord(s[i]) - ord('a'):
			csum[i][j] = csum[i - 1][j] + 1
		else:
			csum[i][j] = csum[i - 1][j]
for i in range(q):
	[l, r] = list(map(int, input().split(' ')))
	l -= 1
	r -= 1
	res = 0
	if l == 0:
		for j in range(26):
			res += csum[r][j] * (j + 1)
	else:
		for j in range(26):
			res += (csum[r][j] - csum[l - 1][j]) * (j + 1)
	print(res)


import sys
(n, p) = map(int, sys.stdin.readline().split())
string = sys.stdin.readline().rstrip()
ans = [0 for _ in range(len(string) + 1)]
ans[0] = 0
for i in range(len(string)):
	ans[i + 1] = ans[i] + ord(string[i]) - 96
for _ in range(p):
	(l, r) = map(int, sys.stdin.readline().split())
	print(ans[r] - ans[max(l - 1, 0)])


import sys
import os.path
import math
import heapq
from sys import stdin, stdout
from collections import *
from math import gcd, ceil, floor
mod = int(1000000000.0 + 7)
if os.path.exists('Updated prg/Input3d.txt'):
	sys.stdout = open('Updated prg/Output3d.txt', 'w')
	sys.stdin = open('Updated prg/Input3d.txt', 'r')

def sinp():
	return input()

def ninp():
	return int(sinp())

def mapinp():
	return map(int, sinp().split())

def linp():
	return list(mapinp())

def sl():
	return list(sinp())

def prnt(a):
	print(a)

def prntl(a):
	print(a, end=' ')

def prntlist(l1):
	print(*l1)

def power(n):
	return 1 << n
(n, q) = mapinp()
s = sinp()
s = s.upper()
l1 = []
for i in range(n):
	l1.append(ord(s[i]) - 65 + 1)
l2 = [0] * n
l2[0] = l1[0]
for i in range(1, n):
	l2[i] = l1[i] + l2[i - 1]
for _ in range(q):
	(l, r) = mapinp()
	(l, r) = (l - 1, r - 1)
	if l > 0:
		s2 = l2[r] - l2[l - 1]
	else:
		s2 = l2[r]
	prnt(s2)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
from itertools import accumulate as ac
from random import randint as ri
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = 1
for _ in range(t):
	(n, q) = inp()
	s = ips()
	ele = 'abcdefghijklmnopqrstuvwxyz'
	pt = 1
	dic = {}
	for i in ele:
		dic[i] = pt
		pt += 1
	pref = [None] * n
	p = 0
	c = 0
	for i in s:
		p += dic[i]
		pref[c] = p
		c += 1
	for i in range(q):
		(l, r) = inp()
		r -= 1
		l -= 1
		ans = pref[r] - pref[l] + dic[s[l]]
		print(ans)


from collections import deque, defaultdict
from math import sqrt, ceil, factorial, floor, inf, log2, sqrt, gcd
import bisect
import copy
from itertools import combinations
import sys

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
from collections import defaultdict
(n, q) = get_ints()
s = input()
dp = [[0 for i in range(26)] for j in range(len(s))]
for i in range(len(s)):
	dp[i][ord(s[i]) - 97] += 1
	if i - 1 >= 0:
		for j in range(26):
			dp[i][j] += dp[i - 1][j]
for i in range(q):
	(x, y) = get_ints()
	x -= 1
	y -= 1
	ans = 0
	for j in range(26):
		if x - 1 >= 0:
			ans += (dp[y][j] - dp[x - 1][j]) * (j + 1)
		else:
			ans += dp[y][j] * (j + 1)
	print(ans)


(a, b) = map(int, input().split())
s = input()
dic = {}
i = 0
anss = 0
for t in s:
	i += 1
	val = ord(t) - 96
	anss += val
	dic[i] = anss
for t in range(b):
	(c, d) = map(int, input().split())
	if c == 1:
		print(dic.get(d))
	else:
		print(dic.get(d) - dic.get(c - 1))


import sys
user_input = sys.stdin.read().splitlines()
song = [ord(i) - 96 for i in user_input[1]]
data = []
for (i, v) in enumerate(song):
	if i == 0:
		data.append(v)
	else:
		data.append(data[i - 1] + v)
sum = 0
questions = user_input[2:]
for question in questions:
	(first, last) = list(map(int, question.split(' ')))
	if first == 1:
		print(data[last - 1])
	else:
		print(data[last - 1] - data[first - 2])


import collections
(n, q) = list(map(int, input().split()))
s = input()
arr = [0]
for s2 in s:
	arr.append(ord(s2) - ord('a') + 1 + arr[-1])
for _ in range(q):
	(i, j) = list(map(int, input().split()))
	print(arr[j] - arr[i - 1])


import bisect
from math import ceil
from sys import stdin

def A():
	k = stdin.readline()
	k = int(k)
	while k:
		k -= 1
		a = [int(x) for x in stdin.readline().split()]
		(n, x, t) = (a[0], a[1], a[2])
		res = 0
		c = t + 0 * x
		c = ceil(c / x)
		if n - c <= 0:
			res += min(c, n) * min(c - 1, n - 1) / 2
		else:
			res += min(c - 1, n - 1) * (n - c + 1)
			res += (n - c) * (n - c + 1) / 2
		print(int(res))

def B():
	a = [int(x) for x in stdin.readline().split()]
	(n, q) = (a[0], a[1])
	s = stdin.readline()
	res = [0] * n
	res[0] = int(ord(s[0]) - 97 + 1)
	for i in range(1, n):
		res[i] = res[i - 1] + int(ord(s[i]) - ord('a') + 1)
	while q:
		q -= 1
		b = [int(x) for x in stdin.readline().split()]
		(l, r) = (b[0], b[1] - 1)
		if b[0] == 1:
			print(res[r])
		else:
			print(res[r] - res[l - 2])
B()


def song_len(lst, l, r):
	return lst[r] - lst[l - 1]
a = input().split()
string = input()
s = [0]
for i in string:
	s.append(ord(i) - 96 + s[-1])
arr = []
for i in range(int(a[1])):
	b = input().split()
	arr.append(song_len(s, int(b[0]), int(b[1])))
for i in arr:
	print(i)


(n, q) = map(int, input().split())
s = input()
p_sums = [0] * (n + 1)
alphabet = 'abcdefghijklmnopqrstuvwxyz'
sum = 0
for i in range(n):
	sum += alphabet.index(s[i]) + 1
	p_sums[i + 1] = sum
for p in range(q):
	(l, r) = map(int, input().split())
	print(p_sums[r] - p_sums[l - 1])


from collections import defaultdict, Counter
from math import sqrt, log10, log2, log, gcd, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from itertools import combinations, combinations_with_replacement
import sys, io, os
input = sys.stdin.readline
mod = 10 ** 9 + 7
inf = float('inf')

def get_list():
	return [int(i) for i in input().split()]

def yn(a):
	print('YES' if a else 'NO')
t = 1
for i in range(t):
	(n, k) = [int(i) for i in input().split()]
	s = input().strip()
	m = []
	for i in range(k):
		m.append([int(i) for i in input().split()])
	prefix = [0]
	for i in s:
		prefix.append(prefix[-1] + (ord(i) - 96))
	for i in m:
		print(prefix[i[1]] - prefix[i[0] - 1])


TC = 1
for tc in range(TC):
	(N, Q) = map(int, input().split())
	S = input()
	P = [0 for _ in range(N + 1)]
	for i in range(1, N + 1):
		P[i] += P[i - 1] + ord(S[i - 1]) - ord('a') + 1
	for _ in range(Q):
		(l, r) = map(int, input().split())
		print(P[r] - P[l - 1])


def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def msi():
	return map(str, input().split())

def li():
	return list(mi())
(n, q) = mi()
s = si()
dp = [0] + [ord(s[0]) - 96] + [0] * (n - 1)
for i in range(1, n):
	dp[i + 1] = dp[i] + ord(s[i]) - 96
for i in range(q):
	(l, r) = mi()
	print(dp[r] - dp[l - 1])


(n, q) = map(int, input().split())
s = list(input())
l = []
l.append(ord(s[0]) - ord('a') + 1)
for i in range(1, n):
	l.append(ord(s[i]) - ord('a') + l[i - 1])
	l[-1] += 1
for _ in range(q):
	(a, b) = map(int, input().split())
	if a == 1:
		print(l[b - 1])
	else:
		print(l[b - 1] - l[a - 2])


def love_song(string, n, q):
	a = [0]
	for i in range(0, len(string)):
		a.append(a[i] + ord(string[i]) - 96)
	for _ in range(0, q):
		(l, r) = list(map(int, input().split()))
		print(a[r] - a[l - 1])
(n, q) = list(map(int, input().split()))
string = input()
love_song(string, n, q)


(n, q) = map(int, input().split())
s = input()
dic = []
temp = [0] * 26
for i in s:
	temp[ord(i) - ord('a')] += 1
	dic.append(temp[:])
for k in range(q):
	(i, j) = map(int, input().split())
	ans = 0
	for z in range(26):
		if i == 1:
			ans += (z + 1) * dic[j - 1][z]
		else:
			ans += (z + 1) * (dic[j - 1][z] - dic[i - 2][z])
	print(ans)


d = {chr(i): i + 1 - 97 for i in range(97, 123)}
(n, q) = map(int, input().split())
s = input()
ans = 0
arr = []
for i in s:
	ans += d[i]
	arr.append(ans)
for _ in range(q):
	(l, r) = map(int, input().split())
	if l == 1:
		print(arr[r - 1])
	else:
		print(arr[r - 1] - arr[l - 2])


import sys
input = sys.stdin.readline
(n, T) = map(int, input().split())
s = input().rstrip()
data = [0]
for (i, t) in enumerate(s):
	data.append(ord(t) - ord('a') + 1 + data[-1])
for _ in range(T):
	(a, b) = map(int, input().split())
	print(data[b] - data[a - 1])


from sys import stdin
_input = stdin.readline
(_enumerate, _dict, _str, _int, _range) = (enumerate, dict, str, int, range)
from string import ascii_lowercase
from collections import defaultdict

def solution():
	d = defaultdict(_int)
	for (index, val) in _enumerate(ascii_lowercase):
		d[val] = index + 1
	(n, q) = [_int(i) for i in _input().split()]
	s = [d[i] for i in _input().rstrip('\n')]
	pref = [0] * (n + 1)
	for i in _range(1, n + 1):
		pref[i] = pref[i - 1] + s[i - 1]
	ans = 0
	for i in _range(q):
		(l, r) = [_int(i) for i in _input().split()]
		print(pref[r] - pref[l - 1])
solution()


def I():
	return input()

def II():
	return int(I())

def M():
	return map(int, I().split())

def L():
	return list(M())
d = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
(n, q) = M()
s = I()
a = [0] * n
a[0] = d.get(s[0])
for i in range(1, n):
	a[i] = a[i - 1] + d.get(s[i])
for _ in range(q):
	(l, r) = M()
	if l < 2:
		c = a[r - 1]
	else:
		c = a[r - 1] - a[l - 2]
	print(c)


from sys import stdin

def solve(string: str, l: int, r: int) -> int:
	count = 0
	for char in string[l - 1:r].rstrip():
		count += ord(char) - 96
	return count

def main():
	nums = list(map(int, stdin.readline().split()))
	string = stdin.readline().rstrip()
	counts = [0] * len(string)
	counts[0] = ord(string[0]) - 96
	for (i, char) in enumerate(string[1:]):
		counts[i + 1] = counts[i] + ord(char) - 96
	for _ in range(nums[1]):
		indices = list(map(int, stdin.readline().split()))
		(l, r) = (indices[0], indices[1])
		if l > 1:
			print(counts[r - 1] - counts[l - 2])
		else:
			print(counts[r - 1])
main()


from sys import stdin, stdout
(n, q) = map(int, stdin.readline().split())
s = stdin.readline()
ls = []
c = 0
for i in range(n):
	c += ord(s[i]) - 96
	ls.append(c)
for _ in range(q):
	(l, r) = map(int, stdin.readline().split())
	if l != 1:
		print(ls[r - 1] - ls[l - 2])
	else:
		print(ls[r - 1])


(n, q) = input().split()
string = str(input())
L = []
answer = 0
for i in range(len(string)):
	answer += ord(string[i]) - 96
	L.append(answer)
for i in range(int(q)):
	(a, b) = input().split()
	if int(a) == 1:
		print(L[int(b) - 1])
	else:
		print(L[int(b) - 1] - L[int(a) - 2])


import sys
input = sys.stdin.readline
(length, questions) = map(int, input().split())
song = list(input())
song.pop()
song = [0] + [ord(x) - 96 for x in song]
psa = [0] * (length + 1)
for i in range(1, length + 1):
	psa[i] = psa[i - 1] + song[i]
for j in range(questions):
	(a, b) = map(int, input().split())
	print(psa[b] - psa[a - 1])


from collections import Counter
(n, q) = [int(_) for _ in input().split()]
s = input()
ps = [0]
for i in s:
	ps += (ps[-1] + ord(i) - 96,)
for t in range(q):
	(l, r) = [int(_) for _ in input().split()]
	print(ps[r] - ps[l - 1])


from functools import lru_cache
from collections import defaultdict

class LoveSong:

	def __init__(self, song: str):
		self.dic = defaultdict(int)
		start_dic = defaultdict(int)
		self.ind_dic = defaultdict(int)
		ind = 1
		for letter in 'abcdefghijklmnopqrstuvwxyz':
			self.ind_dic[letter] = ind
			ind += 1
		score = 0
		for (ind, letter) in enumerate(song):
			score += self.ind_dic[letter]
			self.dic[ind] = score

	def getModSongLength(self, left: int, right: int) -> int:
		if left > 0:
			left_score = self.dic[left - 1]
		else:
			left_score = 0
		right_score = self.dic[right - 1]
		return right_score - left_score
line1 = input()
len_song = int(line1.split(' ')[0])
questions = int(line1.split(' ')[1])
song = input()
sol = LoveSong(song)
for q in range(questions):
	range = input()
	left = int(range.split(' ')[0])
	right = int(range.split(' ')[1])
	print(sol.getModSongLength(left - 1, right))


(n, q) = map(int, input().split())
s = input()
l = []
for j in range(n):
	l.append(ord(s[j]) - 96)
pref_sum = [l[0]]
for j in range(1, n):
	pref_sum.append(pref_sum[-1] + l[j])
for j in range(q):
	(L, r) = map(int, input().split())
	print(pref_sum[r - 1] - pref_sum[L - 1] + l[L - 1])


(n, q) = map(int, input().split())
s = input()
dp = []
ans = 0
for i in range(1, n + 1):
	dp.append(ans)
	ans += ord(s[i - 1]) - 96
dp.append(ans)
for _ in range(q):
	(left, right) = map(int, input().split())
	print(dp[right] - dp[left - 1])


p = [int(i) for i in input().split()]
n = p[0]
q = p[1]
s = input()
l = []
l.append(0)
k = 0
for i in s:
	k = k + ord(i) - 97 + 1
	l.append(k)
for i in range(q):
	p = [int(j) for j in input().split()]
	print(l[p[1]] - l[p[0] - 1])


(a, b) = map(int, input().split())
pl = 'abcdefghijklmnopqrstuvwxyz'
v = {}
for i in range(len(pl)):
	if pl[i] not in v.keys():
		v[pl[i]] = i + 1
s = input()
l = {}
count = 0
for i in range(len(s)):
	count += v[s[i]]
	if i + 1 not in l.keys():
		l[i + 1] = count
for i in range(b):
	(m, n) = map(int, input().split())
	if m == 1:
		print(l[n])
	else:
		print(l[n] - l[m - 1])


def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum
karmanya = 1
while karmanya != 0:
	karmanya -= 1
	(n, q) = map(int, input().split())
	s = list(input())
	pos = []
	for i in s:
		pos.append(ord(i) - 96)
	prefixArray = pref(pos)
	for i in range(q):
		(l, r) = map(int, input().split())
		print(prefixArray[r] - prefixArray[l - 1])


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())
(n, q) = get_ints()
text = input()
arr = []
for i in range(len(text)):
	if i == 0:
		arr.insert(i, ord(text[i]) - 96)
	else:
		arr.insert(i, arr[i - 1] + ord(text[i]) - 96)
for j in range(int(q)):
	(k, l) = get_ints()
	if k != l:
		ans = arr[l - 1] - arr[k - 1] + ord(text[k - 1]) - 96
	else:
		ans = ord(text[k - 1]) - 96
	print(ans)


from sys import stdin
input = stdin.readline
from itertools import accumulate

def solve():
	(n, q) = [int(char) for char in input().split()]
	s = input()
	count_arr = [0] + [ord(char) - 96 for char in s]
	acc = list(accumulate(count_arr))
	for _ in range(q):
		(l, r) = map(int, input().split())
		print(acc[r] - acc[l - 1])
solve()


(n, q) = map(int, input().split())
song = input()
alphabet = {'abcdefghijklmnopqrstuvwxyz'[i]: i + 1 for i in range(26)}
dp = [0] * n
for i in range(n):
	dp[i] = dp[i - 1] + alphabet[song[i]]
res = ''
for _ in range(q):
	(l, r) = map(int, input().split())
	if l == 1:
		res += '%d\n' % dp[r - 1]
	else:
		res += '%d\n' % (dp[r - 1] - dp[l - 2])
print(res)


(n, k) = map(int, input().split())
s = input()
ans = [0] * (n + 1)
for i in range(1, n + 1):
	ans[i] = ans[i - 1] + ord(s[i - 1]) - 96
for _ in range(k):
	(l, r) = map(int, input().split())
	print(ans[r] - ans[l - 1])


(n, q) = map(int, input().split())
s = input()
inds = list(range(n))
new_s = ''
for i in range(n):
	k = ord(s[i]) - ord('a') + 1
	new_s += s[i] * k
	if i + 1 < n:
		inds[i + 1] = inds[i] + k
for _ in range(q):
	(l, r) = map(lambda x: int(x) - 1, input().split())
	print(inds[r] - inds[l] + (ord(s[r]) - ord('a') + 1))


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, q) = [int(x) for x in input().split()]
s = list(input())
temp = [[0] * 26 for i in range(n + 1)]
for i in range(1, n + 1):
	temp[i] = temp[i - 1][:]
	temp[i][ord(s[i - 1]) - ord('a')] += 1
for _ in range(q):
	(a, b) = [int(x) for x in input().split()]
	now = temp[b][:]
	for i in range(26):
		now[i] -= temp[a - 1][i]
	ans = 0
	for i in range(26):
		ans += now[i] * (i + 1)
	print(ans)


(n, q) = map(int, input().split())
s = str(input())
dp = [0 for i in range(n)]
c = 0
for i in range(n):
	c += ord(s[i]) - 96
	dp[i] = c
for i in range(q):
	(l, k) = map(int, input().split())
	if l <= 1:
		if k <= 1:
			print(dp[i - 1])
		else:
			print(dp[k - 1])
	else:
		print(dp[k - 1] - dp[l - 2])


from string import ascii_lowercase as asc
alphabet = {asc[i]: i + 1 for i in range(len(asc))}
(n, q) = [int(x) for x in input().split()]
stroke = input()
sums = []
for i in stroke:
	sums.append(sums[-1] + alphabet[i] if sums != [] else alphabet[i])
for i in range(q):
	(l, r) = [int(x) - 1 for x in input().split()]
	l -= 1
	if l < 0:
		print(sums[r])
	else:
		print(sums[r] - sums[l])


(n, q) = map(int, input().split())
s = input()
dic = {chr(i + 96): i for i in range(1, 27)}
presum = [dic[s[0]]]
for i in range(1, len(s)):
	presum.append(presum[i - 1] + dic[s[i]])
for _ in range(q):
	(l, r) = map(int, input().split())
	print(presum[r - 1] - (presum[l - 2] if l >= 2 else 0))


t = 1
for _ in range(t):
	(n, q) = map(int, input().split())
	s = input()
	pre = [[0 for j in range(27)] for i in range(n + 1)]
	for i in range(n):
		for j in range(1, 27):
			if ord(s[i]) - 96 == j:
				pre[i + 1][ord(s[i]) - 97 + 1] = pre[i][ord(s[i]) - 97 + 1] + 1
			else:
				pre[i + 1][j] = pre[i][j]
	for j in range(q):
		(l, r) = map(int, input().split())
		ans = 0
		for j in range(1, 27):
			res = pre[r][j] - pre[l - 1][j]
			ans += res * j
		print(ans)


def cast(cre, typ):
	return type(typ)(map(cre, typ))

def inp_lis(cre):
	if cre == str:
		return input().split()
	elif cre == bool:
		return cast(bool, cast(int, input().split()))
	else:
		return cast(cre, input().split())

def repl(str_, idx=-1, char=''):
	leng = len(str_)
	return str_[:idx] + char + str_[(leng + idx) % leng + 1:]

def testcase():
	(n, q) = inp_lis(int)
	s = input()
	lr = [inp_lis(int) for i in range(q)]
	(l, r) = (0, 1)
	ref = 'abcdefghijklmnopqrstuvwxyz'
	dic = {}
	for i in range(len(ref)):
		if ref[i] in dic:
			dic[ref[i]] = i + 1
		else:
			dic[ref[i]] = i + 1
	v = [0] * n
	for i in range(n):
		v[i] = dic[s[i]] + v[i - 1]
	for i in range(q):
		ans = v[lr[i][r] - 1] - (v[lr[i][l] - 2] if lr[i][l] > 1 else 0)
		print(ans)
	return

def solution():
	for t in range(int(input())):
		testcase()
	return
testcase()


(n, t) = map(int, input().split())
s = input()
a = [0] * n
a[0] = ord(s[0]) - 96
for i in range(1, n):
	a[i] = a[i - 1] + ord(s[i]) - 96
for _ in range(t):
	(l, r) = map(int, input().split())
	if l > 1:
		print(a[r - 1] - a[l - 2])
	else:
		print(a[r - 1])


import string

def intlist():
	return [int(i) for i in input().split(' ')]

def stringlist():
	return input().split(' ')

def yes(t):
	if t:
		return 'YES'
	return 'NO'

def printjoin(l, str=False):
	if str:
		l = [str(i) for i in l]
	return ' '.join(l)

def power_of_two(n):
	b = bin(n)[2:]
	return int(b) == 10 ** (len(b) - 1)

def bit_count(n):
	return bin(n).count('1')

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	lcm = x * y // gcd(x, y)
	return lcm

def isint(str):
	try:
		int(str)
		return True
	except ValueError:
		return False

def solve():
	l = list(string.ascii_lowercase)
	d = {}
	n = 1
	for i in l:
		d[i] = n
		n += 1
	(n, q) = intlist()
	s = input()
	ques = []
	for i in range(q):
		l = intlist()
		ques.append(l)
	ans = []
	ans.append(d[s[0]])
	for i in range(1, n):
		ans.append(d[s[i]] + ans[-1])
	ans1 = [0] * n
	ans1[-1] = d[s[-1]]
	for i in range(n - 2, -1, -1):
		ans1[i] = d[s[i]] + ans1[i + 1]
	for i in ques:
		print(ans[i[1] - 1] - (ans1[0] - ans1[i[0] - 1]))
	return ''
print(solve())


import sys
(length_of_song, number_of_questions) = map(int, sys.stdin.readline().split())
song = sys.stdin.readline()[:-1]
letters_and_values = dict()
value = 1
for letter in 'abcdefghijklmnopqrstuvwxyz':
	letters_and_values[letter] = value
	value = value + 1
song_weights = [0]
current_weight = 0
for letter in song:
	current_weight = current_weight + letters_and_values[letter]
	song_weights.append(current_weight)
for _ in range(number_of_questions):
	(left, right) = map(int, sys.stdin.readline().split())
	print(song_weights[right] - song_weights[left - 1])


(n, q) = list(map(int, input().split()))
slowo = input()
zapytania = []
w = {}
for i in range(1, 27):
	w[chr(i + 96)] = i
tab = [0] * (n + 1)
tab[0] = w[slowo[0]]
for i in range(q):
	zapytania.append(list(map(int, input().split())))
for i in range(1, n):
	tab[i] = tab[i - 1] + w[slowo[i]]
for i in zapytania:
	print(tab[i[1] - 1] - tab[i[0] - 2])


(n, q) = map(int, input().split())
a = input()
ans = []
pr = [0]
for i in a:
	pr.append(ord(i) - ord('a') + 1 + pr[-1])
for _ in range(q):
	(l, r) = map(int, input().split())
	ans.append(pr[r] - pr[l - 1])
for i in ans:
	print(i)


import string

def solve():
	(n, q) = map(int, input().split())
	s = input()
	d = {}
	ans = 0
	l = [0] * (n + 1)
	for i in range(1, n + 1):
		l[i] = l[i - 1] + (ord(s[i - 1]) - 96)
	for _ in range(q):
		(r, e) = map(int, input().split())
		print(l[e] - l[r - 1])
solve()


import string
(n, q) = map(int, input().split(' '))
s = input().strip()
C = []
for c in string.ascii_lowercase:
	L = [0, 1 if s[0] == c else 0]
	for i in range(1, len(s)):
		L.append(L[-1] + (1 if s[i] == c else 0))
	C.append(L)
for _ in range(q):
	(l, r) = map(int, input().split(' '))
	print(sum(((C[i][r] - C[i][l - 1]) * (i + 1) for i in range(len(string.ascii_lowercase)))))


import string
from pprint import pprint

def cou(s):
	d = {c: [0] for c in set(s)}
	for c in s:
		for cc in d:
			d[cc].append(d[cc][-1] + int(cc == c))
	return d

def query(d, l, r):
	dd = {c: d[c][r] - d[c][l - 1] for c in d}
	return sum([(ord(c) - 96) * v for (c, v) in dd.items()])
(n, q) = map(int, input().split())
s = input()
d = cou(s)
for _ in range(q):
	(l, r) = map(int, input().split())
	print(query(d, l, r))


def solve1(l, a, b):
	if a == 1:
		return l[b - 1]
	else:
		return l[b - 1] - l[a - 2]

def solve(s, n, k):
	nn = len(s)
	l = [0] * nn
	l[0] = ord(s[0]) - 96
	for i in range(1, nn):
		l[i] = l[i - 1] + (ord(s[i]) - 96)
	for i in range(k):
		(a, b) = map(int, input().split())
		print(solve1(l, a, b))
(n, k) = map(int, input().split())
s = input()
solve(s, n, k)


from os import environ
import sys
if environ.get('hardik'):
	sys.stdin = open('../input.txt', 'r')
	sys.stdout = open('../output.txt', 'w')
input = sys.stdin.readline
(n, q) = map(int, input().split())
s = input()
arr = [[0 for x in range(26)] for i in range(n)]
arr[0][ord(s[0]) - 97] = 1
for i in range(1, n):
	for x in range(26):
		arr[i][x] = arr[i - 1][x]
	arr[i][ord(s[i]) - 97] += 1
for i in range(q):
	(l, r) = map(int, input().split())
	l -= 1
	r -= 1
	summation = 0
	occurences = [0 for x in range(26)]
	if not l == 0:
		for i in range(26):
			summation += (arr[r][i] - arr[l - 1][i]) * (i + 1)
	else:
		for i in range(26):
			summation += arr[r][i] * (i + 1)
	print(summation)


from collections import defaultdict
import math
for _ in range(1):
	d = defaultdict(lambda : 0)
	(n, k) = map(int, input().split())
	s = input()
	arr = [0] * 26
	ar = arr + []
	l = []
	l.append(ar)
	for i in s:
		arr[ord(i) - 97] += 1
		ar = arr + []
		l.append(ar)
	for i in range(k):
		(a, b) = map(int, input().split())
		x = l[a - 1]
		y = l[b]
		ans = 0
		for i in range(26):
			ans += (y[i] - x[i]) * (i + 1)
		print(ans)


l = [*open(0)][1:]
s = l[0]
k = [0]
for x in s:
	k += (k[-1] + ord(x) - 96,)
for i in l[1:]:
	d = i.split()
	print(k[int(d[1])] - k[int(d[0]) - 1])


import sys
input = sys.stdin.readline
(n, q) = map(int, input().split())
s = input()
temp = [0]
for i in range(len(s)):
	temp.append(temp[-1] + ord(s[i]) - ord('a') + 1)
while q > 0:
	q -= 1
	(l, r) = map(int, input().split())
	print(temp[r] - temp[l - 1])


line_1 = list(map(int, input().split()))
(song_len, queries_len) = line_1
song_string = input()
decrease = lambda num: int(num) - 1
queries = [list(map(decrease, input().split())) for _ in range(queries_len)]
english_alph = 'a b c d e f g h i j k l m n o p q r s t u v w x y z'
english_alph = {item: i + 1 for (i, item) in enumerate(english_alph.split())}
counter_len = [0] * song_len
for i in range(song_len):
	letter = song_string[i]
	counter_len[i] = english_alph[letter]
	if i > 0:
		counter_len[i] += counter_len[i - 1]
j = 0
counter_len_2 = []
for q in range(queries_len - 1, -1, -1):
	(start, end) = queries[j]
	j += 1
	total_len = 0
	total_len += counter_len[end]
	if start > 0:
		total_len -= counter_len[start - 1]
	counter_len_2.append(str(total_len))
print('\n'.join(counter_len_2))


import sys
input = sys.stdin.readline

def main():
	(n, q) = map(int, input().split())
	S = input().strip()
	cum = [0]
	for s in S:
		cum.append(cum[-1] + ord(s) - 96)
	for _ in range(q):
		(l, r) = map(int, input().split())
		print(cum[r] - cum[l - 1])
for _ in range(1):
	main()


(n, q) = map(int, input().split())
s = input()
arr = [0] * (n + 1)
t = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
dic = {}
for i in range(len(t)):
	if t[i] not in dic:
		dic[t[i]] = i + 1
for i in range(0, n):
	if i == 0:
		arr[1] = dic[s[i]]
	else:
		arr[i + 1] = dic[s[i]] + arr[i]
for i in range(q):
	(l, r) = map(int, input().split())
	print(arr[r] - arr[l - 1])


from sys import stdin
(_, q) = map(int, stdin.readline().split())
s_len = [0]
for ch in stdin.readline():
	s_len.append(s_len[-1] + ord(ch) - 96)
for _ in range(q):
	(l, r) = map(int, stdin.readline().split())
	print(s_len[r] - s_len[l - 1])


(n, q) = map(int, input().split())
s = input()
mk = [0]
c = 0
for i in s:
	c = c + (ord(i) - 96)
	mk.append(c)
for i in range(q):
	(l, r) = map(int, input().split())
	print(mk[r] - mk[l - 1])


import os
import sys
from io import BytesIO, IOBase

def main():
	(n, q) = map(int, input().split())
	s = list(input())
	pref = [[0 for i in range(26)] for j in range(n + 1)]
	for i in range(1, n + 1):
		pref[i][ord(s[i - 1]) - 97] += 1
		for j in range(26):
			pref[i][j] = pref[i - 1][j] + pref[i][j]
	for i in range(q):
		(l, r) = map(int, input().split())
		ans = 0
		for j in range(26):
			ans = ans + (pref[r][j] - pref[l - 1][j]) * (j + 1)
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, q) = map(int, input().split())
s = input()
ans = [0]
for x in s:
	ans.append(ans[-1] + ord(x) - 96)
for i in range(q):
	(l, r) = map(int, input().split())
	print(ans[r] - ans[l - 1])


import sys
input = sys.stdin.readline

def solve():
	(n, q) = map(int, input().split())
	s = input().strip()
	p = [0] * (n + 1)
	A = ord('a')
	for i in range(n):
		p[i + 1] = p[i] + ord(s[i]) - A + 1
	for i in range(q):
		(l, r) = map(int, input().split())
		print(p[r] - p[l - 1])
solve()


[size, query] = [int(x) for x in input().split(' ')]
str = input()
dict = {-1: 0}
for j in range(len(str)):
	dict[j] = dict[j - 1] + (ord(str[j]) - 96)
for i in range(query):
	[l, r] = [int(x) for x in input().split(' ')]
	print(dict[r - 1] - dict[l - 2])


import math

def main(l, r, res):
	l = l - 1
	print(res[r] - res[l])
(_, n) = tuple(map(int, input().split(' ')))
s = input()
res = [0] * (len(s) + 1)
for i in range(1, len(s) + 1):
	res[i] = res[i - 1] + ord(s[i - 1]) - 96
for i in range(n):
	main(*list(map(int, input().split(' '))), res)


(s, *l) = [*open(0)][1:]
k = [0]
for x in s:
	k += (k[-1] + ord(x) - 96,)
for i in l:
	(a, b) = map(int, i.split())
	print(k[b] - k[a - 1])


(n, q) = map(int, input().split())
s = input()
a = [0]
for i in s:
	num = ord(i)
	a.append(num - 96)
for i in range(1, n + 1):
	a[i] += a[i - 1]
for i in range(q):
	(x, y) = map(int, input().split())
	print(a[y] - a[x - 1])


from bisect import bisect_left
import math
import re
import string
import sys
from itertools import permutations
from collections import Counter
import itertools
MOD = 1000000007

def inp():
	return map(int, input().split(' '))

def ninp():
	return int(input())
(n, q) = inp()
s = input()
a = [0]
res = 0
for i in s:
	res += ord(i) - 96
	a.append(res)
for _ in range(q):
	(x, y) = inp()
	print(a[y] - a[x - 1])


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().rstrip().split())
inl = lambda : list(map(int, input().split()))
out = lambda x, s='\n': print(s.join(map(str, x)))
(q, n) = inm()
s = ins()
ans = [0] * (q + 1)
for i in range(1, q + 1):
	ans[i] += ans[i - 1] + ord(s[i - 1]) - 96
for _ in range(n):
	(l, r) = inm()
	print(ans[r] - ans[l - 1])


import sys
(n, q) = map(int, sys.stdin.readline().split())
word = list(map(lambda x: ord(x) - 96, sys.stdin.readline().strip()))
sub_sum = [0, word[0]]
for i in range(n - 1):
	sub_sum.append(sub_sum[-1] + word[i + 1])
for _ in range(q):
	(l, r) = map(int, sys.stdin.readline().split())
	print(sub_sum[r] - sub_sum[l - 1])


(n, q) = map(int, input().split(' '))
s = str(input())
list = []
sum = 0
for i in s:
	sum += ord(i) - 96
	list.append(sum)
for q in range(1, q + 1):
	(l, r) = map(int, input().split(' '))
	if l == 1:
		a = list[r - 1]
	else:
		a = list[r - 1] - list[l - 2]
	print(a)


(n, q) = map(int, input().split())
s = input()
cnt = [[0] * 26 for _ in range(n)]
for i in range(n):
	if i == 0:
		cnt[i][ord(s[i]) - ord('a')] += 1
	else:
		for j in range(26):
			if ord(s[i]) - ord('a') == j:
				cnt[i][j] += 1
			cnt[i][j] += cnt[i - 1][j]
for _ in range(q):
	(L, R) = map(int, input().split())
	L -= 1
	R -= 1
	res = 0
	if L == 0:
		for i in range(26):
			res += (i + 1) * cnt[R][i]
	else:
		for i in range(26):
			res += (i + 1) * (cnt[R][i] - cnt[L - 1][i])
	print(res)


import sys
l = sys.stdin.readlines()
(n, q) = [int(x) for x in l[0].replace('\n', '').split()]
s = l[1].replace('\n', '')
dic = {1: ord(s[0]) - 96}
for k in range(2, len(s) + 1):
	dic[k] = dic[k - 1] + ord(s[k - 1]) - 96
for i in range(2, q + 2):
	(ini, fim) = [int(x) for x in l[i].replace('\n', '').split()]
	if ini == 1:
		print(dic[fim])
	else:
		print(dic[fim] - dic[ini - 1])


(n, q) = map(int, input().split())
k1 = []
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
k = []
d = 0
for j in input():
	d = d + (alphabet.index(j) + 1)
	k.append(d)
for i in range(q):
	(l, r) = map(int, input().split())
	x = 0
	if l > 1:
		x = k[r - 1] - k[l - 1 - 1]
	else:
		x = k[r - 1]
	k1.append(x)
for t in k1:
	print(t)


import math
import sys
import itertools
import fractions
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
(n, q) = map(int, wtf[0].split())
s = wtf[1]
a_id = ord('a') - 1
mem = [0]
j = 0
for i in range(n):
	k = j + ord(s[i]) - a_id
	j = k
	mem.append(k)
for t in wtf[2:]:
	(l, r) = map(int, t.split())
	ans = mem[r] - mem[l - 1]
	print(ans)


t = 'abcdefghijklmnopqrstuvwxyz'
dd = {t[i]: i + 1 for i in range(len(t))}
(n, q) = map(int, input().split())
l = list(input())
pas = []
h = 0
for i in l:
	c = dd[i]
	h += c
	pas.append(h)
for i in range(q):
	(s, e) = map(int, input().split())
	if s != 1:
		print(pas[e - 1] - pas[s - 2])
	else:
		print(pas[e - 1])


(n, q) = map(int, input().split())
s = input()
pSum = [[0] * len(s) for _ in range(255)]
for i in range(255):
	for x in range(len(s)):
		if x > 0:
			pSum[i][x] = pSum[i][x - 1]
		if ord(s[x]) == i:
			pSum[i][x] += 1
for _ in range(q):
	(l, r) = map(int, input().split())
	r -= 1
	l -= 1
	res = 0
	for i in range(ord('a'), ord('z') + 1):
		left = 0
		if l > 0:
			left = pSum[i][l - 1]
		res += (pSum[i][r] - left) * (i - ord('a') + 1)
	print(res)


import sys, copy
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
(n, q) = invr()
s = insr()
pref = (len(s) + 1) * [0]
for i in range(len(s)):
	pref[i + 1] = pref[i] + ord(s[i]) - ord('a') + 1
for _ in range(q):
	(l, r) = invr()
	print(pref[r] - pref[l - 1])


al = '1abcdefghijklmnopqrstuvwxyz'
(n, q) = map(int, input().split())
l = [0]
s = str(input())
for i in range(len(s)):
	p = al.index(s[i])
	p = p + l[i]
	l.append(p)
for i in range(q):
	(c, d) = map(int, input().split())
	ans = l[d] - l[c - 1]
	print(ans)


import sys
stdin = sys.stdin
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
ns = lambda : stdin.readline().rstrip()
(n, q) = na()
a = tuple(map(ord, tuple(ns())))
s = [a[0] - 96]
for i in range(1, n):
	s.append(s[i - 1] + a[i] - 96)

def main():
	(l, r) = na()
	if l == 1:
		print(s[r - 1])
	else:
		print(s[r - 1] - s[l - 2])
for i in range(q):
	main()


import math
nq = [int(x) for x in input().split()]
n = nq[0]
q = nq[1]
inp = str(input())
a_ascii = ord('a')
num_of_str = []
l = 0
for i in inp:
	if len(num_of_str) == 0:
		num_of_str.append(ord(i) - a_ascii + 1)
	else:
		num_of_str.append(num_of_str[l] + ord(i) - a_ascii + 1)
		l += 1
for i in range(q):
	lr = [int(x) for x in input().split()]
	l = lr[0]
	r = lr[1]
	if l == 1:
		print(num_of_str[r - 1])
	else:
		print(num_of_str[r - 1] - num_of_str[l - 2])


(n, q) = input().split()
n = int(n)
q = int(q)
s = input()
ans = []
temp = [0]
for i in s:
	temp.append(temp[-1] + (ord(i) - 96))
for i in range(q):
	res = 0
	(l, r) = input().split()
	l = int(l)
	r = int(r)
	ans.append(temp[r] - temp[l - 1])
for i in ans:
	print(i)


from math import *
from collections import defaultdict as dt
from sys import *
setrecursionlimit(100000)
inp = lambda : stdin.readline().strip()
I = lambda : int(inp())
M = lambda : map(int, inp().split())
L = lambda : list(M())
mod = 1000000007
inf = 100000000000000000000
ss = 'abcdefghijklmnopqrstuvwxyz'
j = 1
d = dt(lambda : 0)
for i in ss:
	d[i] = j
	j = j + 1

def solve():
	(n, q) = M()
	s = inp()
	c = 0
	e = dt(lambda : 0)
	for i in range(n):
		c = c + d[s[i]]
		e[i + 1] = c
	for _ in range(q):
		(l, r) = M()
		print(e[r] - e[l - 1])
tt = 1
for _ in range(tt):
	solve()


(num_str, num_question) = input().split()
song = input()
if len(song) != int(num_str):
	raise ValueError
song.lower()
char_point = [0]
point = 0
for char in song:
	point += ord(char) - 96
	char_point.append(point)
output = []
for n in range(int(num_question)):
	qustion = input().split()
	start_index = int(qustion[0])
	end_index = int(qustion[1])
	result = char_point[end_index] - char_point[start_index - 1]
	output.append(result)
for print_elem in output:
	print(print_elem)


import string
alph = list(string.ascii_lowercase)
(n, q) = map(int, input().split())
s = input()
d = [i for i in s]
cnt = 0
for i in range(len(s)):
	cnt += alph.index(s[i]) + 1
	d[i] = cnt
for i in range(q):
	(a, b) = map(int, input().split())
	if a - 2 < 0:
		print(d[b - 1])
	else:
		print(d[b - 1] - d[a - 2])


buff = input().split(' ')
n = int(buff[0])
q = int(buff[1])
s = input()
ss = [0]
sum = 0
for i in range(n):
	sum += ord(s[i]) - 96
	ss.append(sum)
for _ in range(q):
	buff = input().split(' ')
	l = int(buff[0])
	r = int(buff[1])
	print(ss[r] - ss[l - 1])


any = 1

def get():
	str = input()
	a = str.split()
	b = []
	for i in range(0, len(a)):
		b.append(int(a[i]))
	if len(b) == 1:
		return b[0]
	else:
		return b

def getarray():
	str = input()
	a = str.split()
	b = []
	for i in range(0, len(a)):
		b.append(int(a[i]))
	return b

def cout(a):
	for i in range(len(a) - 1):
		temp = str(a[i])
		print(temp, end=' ')
	print(str(a[len(a) - 1]))
c = get()
n = c[0]
t = c[1]
arr = input()
li = []
temp = 0
li.append(0)
for i in range(n):
	temp += ord(arr[i]) - 96
	li.append(temp)
for i in range(t):
	q = get()
	print(li[q[1]] - li[q[0] - 1])


(n, q) = map(int, input().split())
al = 'abcdefghijklmnopqrstuvwxyz'
d = {}
for i in range(len(al)):
	if d.get(al[i], 0) == 0:
		d[al[i]] = i + 1
s = input()
lis = []
lis.append(0)
xx = 0
for i in s:
	xx += d[i]
	lis.append(xx)
for i in range(q):
	ccc = 0
	(l, r) = map(int, input().split())
	print(lis[r] - lis[l - 1])


import sys
input = lambda : sys.stdin.readline()
int_arr = lambda : list(map(int, input().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().split())
get_int = lambda : map(int, input().split())
get_flo = lambda : map(float, input().split())
mod = 1000000007
(n, q) = get_int()
dp = [0] * (n + 1)
st = str(input())
for i in range(1, n + 1):
	dp[i] = dp[i - 1] + ord(st[i - 1]) % 97 + 1
for i in range(q):
	(x, y) = get_int()
	print(dp[y] - dp[x - 1])


from collections import Counter
from collections import defaultdict as dfd
from bisect import bisect, bisect_left
from math import sqrt, gcd, ceil, factorial
from heapq import heapify, heappush, heappop
MOD = 10 ** 9 + 7
inf = float('inf')
ans_ = []

def nin():
	return int(input())

def ninf():
	return int(file.readline())

def st():
	return input().strip()

def stf():
	return file.readline().strip()

def read():
	return list(map(int, input().strip().split()))

def readf():
	return list(map(int, file.readline().strip().split()))

def solve():
	(n, q) = read()
	s = st()
	pref = [0] * (n + 1)
	for i in range(n):
		pref[i + 1] += pref[i] + (ord(s[i]) - 96)
	for _ in range(q):
		(l, r) = read()
		ans_.append(pref[r] - pref[l - 1])
solve()
for i in ans_:
	print(i)


(n, q) = map(int, input().split())
arr = input()
arr1 = [ord(arr[0]) - 96]
for i in range(1, n):
	arr1.append(ord(arr[i]) - 96 + arr1[i - 1])
for j in range(q):
	(a, b) = map(int, input().split())
	if a == 1:
		print(arr1[b - 1])
	else:
		print(arr1[b - 1] - arr1[a - 2])


from math import ceil
(n, q) = map(int, input().split())
s = input()

def f(l, r):
	a = 0
	for c in s[l:r + 1]:
		a += ord(c) - 96
	return a
v = 316
d = [f(v * i, v * (i + 1) - 1) for i in range(n // v)]
for i in range(q):
	(l, r) = map(int, input().split())
	(l, r) = (l - 1, r - 1)
	st = l // v
	end = ceil(r // v)
	b = f(l, min(r, (st + 1) * v - 1))
	m = sum((d[j] for j in range(st + 1, end)))
	e = f(end * v, r) if st < end else 0
	print(b + m + e)


(n, q) = map(int, input().split())
arr = list(input())
prefix = [0] * n
for i in range(len(arr)):
	tmp = ord(arr[i]) - 96
	prefix[i] = tmp
for i in range(1, n):
	prefix[i] = prefix[i] + prefix[i - 1]
for i in range(q):
	(l, r) = map(int, input().split())
	l -= 1
	r -= 1
	if l == 0:
		print(prefix[r])
	else:
		print(prefix[r] - prefix[l - 1])


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect, insort
from time import perf_counter
from fractions import Fraction
import copy
from copy import deepcopy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass

def pmat(A):
	for ele in A:
		print(*ele, end='\n')
(n, q) = L()
S = input()
A = [[0 for i in range(n + 1)] for j in range(26)]
for i in range(n):
	for j in range(26):
		A[j][i + 1] = A[j][i] + int(ord(S[i]) - ord('a') == j)
for i in range(q):
	(l, r) = L()
	count = 0
	for j in range(26):
		count += (A[j][r] - A[j][l - 1]) * (j + 1)
	print(count)


import sys
input = sys.stdin.readline
(n, q) = map(int, input().split())
s = input()
v = [0]
for i in range(n):
	v.append(v[-1] + (ord(s[i]) - 96))
for _ in range(q):
	(l, r) = map(int, input().split())
	print(v[r] - v[l - 1])


(m, n) = [int(x) for x in input().split()]
s = {}
s[-1] = 0
cnt = 0
s0 = input()
for i in range(m):
	cnt += ord(s0[i]) - 96
	s[i] = cnt
result = []
for _ in range(n):
	(a, b) = [int(x) for x in input().split()]
	result.append(s[b - 1] - s[a - 2])
print(*result, sep='\n')


from sys import stdin, gettrace
if gettrace():

	def inputi():
		return input()
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def main():
	(n, q) = map(int, input().split())
	ss = list(map(lambda c: ord(c) - ord('a') + 1, input()))
	counts = [[0] * 27]
	for c in ss:
		counts.append(counts[-1].copy())
		counts[-1][c] += 1
	for _ in range(q):
		(l, r) = map(int, input().split())
		res = sum((c * (counts[r][c] - counts[l - 1][c]) for c in range(1, 27)))
		print(res)
main()


(n, q) = map(int, input().split())
s = input()
lst = [0]
ss = 0
for i in s:
	ss += ord(i) - 96
	lst.append(ss)
for _ in range(q):
	(l, r) = map(int, input().split())
	print(lst[r] - lst[l - 1])


from math import factorial, ceil, pow, sqrt, floor, gcd
from sys import stdin, stdout
siri = [0] * 26
for _ in range(1):
	shan = [0]
	(n, x) = map(int, stdin.readline().split())
	s = list(stdin.readline().strip('\n'))
	sumy = 0
	for e in s:
		sumy += ord(e) - ord('a') + 1
		shan.append(sumy)
	for i in range(x):
		(a, b) = map(int, stdin.readline().split())
		print(shan[b] - shan[a - 1])


from string import ascii_lowercase
d = {letter: index for (index, letter) in enumerate(ascii_lowercase, start=1)}
(n, q) = list(map(int, input().split()))
s = list(input())
s = [d[a] for a in s]
p = [0] * n
p[0] = s[0]
i = 1
while i < n:
	p[i] = p[i - 1] + s[i]
	i += 1
while q > 0:
	q -= 1
	(l, r) = list(map(int, input().split()))
	print(p[r - 1] - p[l - 1] + s[l - 1])


from bisect import insort, bisect_right, bisect_left
from sys import stdout, stdin, setrecursionlimit
from math import sqrt, ceil, floor, factorial, gcd, log2, log10
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from string import *
from queue import *
from heapq import *
from re import *
from os import *

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
(graph, mod, szzz) = ({}, 10 ** 9 + 7, lambda : sorted(zzz()))

def getStr():
	return input()

def getInt():
	return int(input())

def listStr():
	return list(input())

def getStrs():
	return input().split()

def isInt(s):
	return '0' <= s[0] <= '9'

def input():
	return stdin.readline().strip()

def zzz():
	return [int(i) for i in input().split()]

def output(answer, end='\n'):
	stdout.write(str(answer) + end)

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def getPrimes(N=10 ** 5):
	SN = int(sqrt(N))
	sieve = [i for i in range(N + 1)]
	sieve[1] = 0
	for i in sieve:
		if i > SN:
			break
		if i == 0:
			continue
		for j in range(2 * i, N + 1, i):
			sieve[j] = 0
	prime = [i for i in range(N + 1) if sieve[i] != 0]
	return prime

def primeFactor(n, prime=getPrimes()):
	lst = []
	mx = int(sqrt(n)) + 1
	for i in prime:
		if i > mx:
			break
		while n % i == 0:
			lst.append(i)
			n //= i
	if n > 1:
		lst.append(n)
	return lst
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
(n, q) = zzz()
arr = getStr()
s = []
for i in range(n):
	s.append(ord(arr[i]) - 96)
s = [0] + list(accumulate(s))
for _ in range(q):
	(l, r) = zzz()
	print(s[r] - s[l - 1])


(n, q) = map(int, input().split())
st = '0' + input()
store = [[0 for i in range(26)] for j in range(n + 2)]
for i in range(1, n + 1):
	store[i][ord(st[i]) - 97] += 1
for i in range(1, n + 1):
	for j in range(26):
		store[i][j] += store[i - 1][j]
for i in range(q):
	(l, r) = map(int, input().split())
	(add, sub) = (0, 0)
	for j in range(26):
		add += (j + 1) * store[r][j]
	for j in range(26):
		sub += (j + 1) * store[l - 1][j]
	print(add - sub)


(n, q) = map(int, input().split())
s = input()
l = [ord(s[0]) - 96]
for i in range(1, len(s)):
	l.append(l[i - 1] + ord(s[i]) - 96)
for i in range(q):
	(lo, r) = map(int, input().split())
	if lo == 1:
		print(l[r - 1])
	else:
		print(l[r - 1] - l[lo - 2])


(L, Q) = map(int, input().split())
song = list(input())
Lsong = []

def convert(N):
	alphabet = 'abcdefghijklmnopqrstuvwxyz'
	N = alphabet.index(N) + 1
	return N

def popopo(L):
	S = [0]
	somme = 0
	for nb in Lsong:
		somme = somme + nb
		S.append(somme)
	return S
for N in song:
	Lsong.append(convert(N))
gigabrain = popopo(Lsong)
for _ in range(Q):
	(A, B) = map(int, input().split())
	print(gigabrain[B] - gigabrain[A - 1])


(n, q) = map(int, input().split())
song = input()
l = [0]
s = 0
for i in song:
	s = s + ord(i) - 96
	l.append(s)
for i in range(0, q):
	(a, b) = map(int, input().split())
	p = l[b] - l[a - 1]
	print(p)


(n, m) = list(map(int, input().split()))
s = list(input())
d = {}
l = [0]
for i in s:
	l.append(l[-1] + 1 + (ord(i) - ord('a')))
for i in range(m):
	(z, y) = list(map(int, input().split()))
	print(l[y] - l[z - 1])


(n, q) = map(int, input().split())
s = input().rstrip()
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
vals = []
for i in range(n):
	vals.append(alphabet.index(s[i]) + 1)
prefsums = [0]
for i in range(n):
	prefsums.append(prefsums[i] + vals[i])
for tc in range(q):
	(l, r) = map(int, input().split())
	print(prefsums[r] - prefsums[l - 1])


(n, q) = map(int, input().split())
s = input()
s = '0' + s
li = [0]
t = 0
for i in range(1, n + 1):
	t += ord(s[i]) - ord('a') + 1
	li.append(t)
for _ in range(q):
	(l, r) = map(int, input().split())
	print(li[r] - li[l - 1])


(n, q) = map(int, input().split())
st = input()
chrArr = [0]
for i in range(n):
	chrArr.append(chrArr[i] + ord(st[i]) - 96)
for _ in range(q):
	(l, r) = map(int, input().split())
	print(chrArr[r] - chrArr[l - 1])


def process(a, q):
	N = len(a)
	freq = [0] * (N + 1)
	for i in range(N):
		freq[i + 1] = freq[i] + (ord(a[i]) - ord('a')) + 1
	ans = []
	for (l, r) in q:
		ans.append(freq[r] - freq[l - 1])
	return ans
(n, q) = [int(_) for _ in input().split(' ')]
ans = []
a = input()
query = []
for i in range(q):
	(l, r) = [int(_) for _ in input().split(' ')]
	query.append((l, r))
ans = process(a, query)
for i in ans:
	print(i)


(n, k) = map(int, input().split())
s = input()
l = [0]
c = 0
for i in s:
	c += ord(i) - 96
	l.append(c)
for _ in range(k):
	(a, b) = map(int, input().split())
	print(l[b] - l[a - 1])


letters = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z')
(n, q) = map(int, input().split())
s = input()
sums = [0]
for k in range(len(s)):
	sums.append(sums[k] + letters.index(s[k]) + 1)
for i in range(q):
	(l, r) = map(int, input().split())
	print(sums[r] - sums[l - 1])


import string
(n, q) = list(map(int, input().split()))
query = [ord(i) - 96 for i in input()]
summation = 0
prefix_sum = []
for t in query:
	summation += t
	prefix_sum.append(summation)
for _ in range(q):
	(l, r) = list(map(int, input().split()))
	l -= 1
	r -= 1
	ans = prefix_sum[r] - (0 if l == 0 else prefix_sum[l - 1])
	print(ans)


import itertools
(n, q) = map(int, input().split())
song = input()
sums = [0]
sums.extend(itertools.accumulate((ord(char) - 96 for char in song)))
results = []
for _ in range(q):
	(l, r) = map(int, input().split())
	results.append(str(sums[r] - sums[l - 1]))
print('\n'.join(results))


(n, q) = map(int, input().split())
s = input()
l = [ord(s[0]) - 96]
for i in range(1, n):
	l.append(l[i - 1] + ord(s[i]) - 96)
for i in range(q):
	(le, ri) = map(int, input().split())
	if le == 1:
		print(l[ri - 1])
	else:
		print(l[ri - 1] - l[le - 2])


from itertools import accumulate
d = {}
for i in range(97, 123):
	d[chr(i)] = i - 96
(n, q) = map(int, input().split())
s = input()
ans = []
for i in s:
	ans.append(d[i])
ans = list(accumulate(ans))
for _ in range(q):
	(l, r) = map(int, input().split())
	if l <= 1:
		print(ans[r - 1])
	else:
		print(ans[r - 1] - ans[l - 2])


(n, q) = map(int, input().split(' '))
s = input()
arr = [[0 for x in range(26)] for x in range(n + 1)]
for i in range(1, n + 1):
	x = arr[i - 1].copy()
	x[ord(s[i - 1]) - 97] += 1
	arr[i] = x
for _ in range(q):
	(l, r) = map(int, input().split(' '))
	a = arr[r]
	b = arr[l - 1]
	curr = 0
	for j in range(26):
		curr = curr + (a[j] - b[j]) * (j + 1)
	print(curr)


import sys
(n, q) = map(int, sys.stdin.readline().split())
data = sys.stdin.readline().rstrip()
dp = [0] * (n + 1)
for i in range(len(data)):
	dp[i + 1] = dp[i] + ord(data[i]) - 96
for _ in range(q):
	(l, r) = map(int, sys.stdin.readline().split())
	print(dp[r] - dp[l - 1])


from sys import stdin, stdout
N = 100000
tree = [0] * (2 * N)

def build(arr):
	for i in range(n):
		tree[n + i] = arr[i]
	for i in range(n - 1, 0, -1):
		tree[i] = tree[i << 1] + tree[i << 1 | 1]

def updateTreeNode(p, value):
	tree[p + n] = value
	p = p + n
	i = p
	while i > 1:
		tree[i >> 1] = tree[i] + tree[i ^ 1]
		i >>= 1

def query(l, r):
	res = 0
	l += n
	r += n
	while l < r:
		if l & 1:
			res += tree[l]
			l += 1
		if r & 1:
			r -= 1
			res += tree[r]
		l >>= 1
		r >>= 1
	return res
(question_n, q) = [int(x) for x in stdin.readline().split()]
s = stdin.readline().strip()
a = []
for c in s:
	a.append(ord(c) - 96)
n = len(a)
build(a)
for _ in range(q):
	(l, r) = [int(x) for x in stdin.readline().split()]
	stdout.write(str(query(l - 1, r)) + '\n')


data = [int(i) for i in input().split()]
length = data[0]
count_test = data[1]
word = input()
count_letters = set(word)
alpabet = 'abcdefghijklmnopqrstuvwxyz'
num = 1
dict_alphabet = {}
for i in alpabet:
	dict_alphabet[i] = num
	num += 1
summ = [0]
for i in range(len(word)):
	summ.append(summ[i] + dict_alphabet[word[i]])
for i in range(count_test):
	data = [int(j) for j in input().split()]
	start = data[0]
	end = data[1]
	print(summ[end] - summ[start - 1])


import sys
from os import path
import math
import time
from collections import defaultdict
from sys import setrecursionlimit
setrecursionlimit(10 ** 8)
MOD = 10 ** 9 + 7
INT_MAX = 10 ** 9
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def binary_search(arr, x, n):
	start = 0
	end = n - 1
	while start <= end:
		mid = (start + end) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			start = mid + 1
		else:
			end = mid - 1
	return end + 1

def test_case():
	(n, Q) = map(int, input().split())
	str_ = input()
	arr = [ord(str_[0]) - 96]
	for i in range(1, n):
		arr.append(arr[i - 1] + ord(str_[i]) - 96)
	arr = [0] + arr
	for q in range(Q):
		(l, r) = map(int, input().split())
		print(arr[r] - arr[l - 1])
test_case()


import bisect
import math
from collections import defaultdict, Counter
import os
import sys
from io import BytesIO, IOBase
ii = lambda : int(input())
lmii = lambda : list(map(int, input().split()))
slmii = lambda : sorted(map(int, input().split()))
li = lambda : list(input())
mii = lambda : map(int, input().split())
msi = lambda : map(str, input().split())

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def main():
	(n, q) = mii()
	s = li()
	cnt = [0]
	for i in range(n):
		cnt.append(cnt[-1] + ord(s[i]) - ord('a') + 1)
	for i in range(q):
		(l, r) = mii()
		print(cnt[r] - cnt[l - 1])
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
from os import path
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
(n, q) = [int(x) for x in input().split()]
s = input()
pre = [0] * len(s)
pre[0] = ord(s[0]) % 32
for i in range(1, len(s)):
	val = ord(s[i]) % 32
	pre[i] = pre[i - 1] + val
for _ in range(q):
	(l, r) = [int(x) for x in input().split()]
	if l == 1:
		print(pre[r - 1])
	else:
		print(pre[r - 1] - pre[l - 2])


from collections import Counter as count
from bisect import bisect
import sys
from math import ceil
from itertools import groupby
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, l) = list(map(int, input().split()))
s = list(input())
s[0] = ord(s[0]) - 96
for i in range(1, n):
	s[i] = ord(s[i]) - 96
	s[i] = s[i] + s[i - 1]
s = [0] + s
for i in range(l):
	(a, b) = list(map(int, input().split()))
	print(s[b] - s[a - 1])


from string import ascii_lowercase

def fun(st, ls, querry):
	(n, q) = ls
	dct = {}
	j = 1
	ans = ''
	temp = ascii_lowercase
	for i in temp:
		if i not in dct:
			dct[i] = j
			j += 1
	prefix_ar = [0 for i in range(n)]
	j = 0
	total_length = 0
	for i in st:
		get_count = dct.get(i)
		ans += i * get_count
		prefix_ar[j] = get_count
		total_length += get_count
		j += 1
	prefix_sum = [0 for i in range(n)]
	for i in range(n):
		if i == 0:
			prefix_sum[i] = prefix_ar[i]
		else:
			prefix_sum[i] = prefix_ar[i] + prefix_sum[i - 1]
	for (i, j) in querry:
		if i != 1:
			print(prefix_sum[j - 1] - prefix_sum[i - 2])
		else:
			print(prefix_sum[j - 1])
T = 1
for i in range(T):
	ls = list(map(int, input().split()))
	st = input()
	querry = []
	for k in range(ls[1]):
		ks = list(map(int, input().split()))
		querry.append(ks)
	fun(st, ls, querry)


(n, t) = map(int, input().split())
s = input()
o = 0
l = []
for i in s:
	o += ord(i) - 96
	l.append(o)
for j in range(t):
	(p, q) = map(int, input().split())
	if p == 1:
		print(l[q - 1])
	else:
		print(l[q - 1] - l[p - 2])


(n, q) = map(int, input().split())
a = list(input())
dp = []
dp.append(0)
s = 0
for k in a:
	s = s + ord(k) % 96
	dp.append(s)
for i in range(q):
	ans = 0
	(l, r) = map(int, input().split())
	ans = dp[r] - dp[l - 1]
	print(ans)


PI = 3.141592653589793
INF = float('inf')
MOD = 1000000007

def add(x, y):
	return (x + y) % MOD

def sub(x, y):
	return (x - y + MOD) % MOD

def mul(x, y):
	return x * y % MOD

def gcd(x, y):
	if y == 0:
		return x
	return gcd(y, x % y)

def lcm(x, y):
	return x * y // gcd(x, y)

def power(x, y):
	res = 1
	x %= MOD
	while y != 0:
		if y & 1:
			res = mul(res, x)
		y >>= 1
		x = mul(x, x)
	return res

def mod_inv(n):
	return power(n, MOD - 2)

def prob(p, q):
	return mul(p, power(q, MOD - 2))

def ii():
	return int(input())

def li():
	return [int(i) for i in input().split()]

def ls():
	return [i for i in input().split()]
(n, q) = li()
s = input()
store = [[0 for i in range(26)] for j in range(n + 1)]
for i in range(n):
	store[i + 1] = store[i][:]
	store[i + 1][ord(s[i]) - 97] += 1
for _ in range(q):
	(l, r) = li()
	final = 0
	for i in range(26):
		cnt = store[r][i] - store[l - 1][i]
		final += (i + 1) * cnt
	print(final)


def solve(l, r):
	return miku[r] - miku[l - 1]
(n, q) = map(int, input().split())
s = input()
miku = [0] * (n + 1)
for i in range(1, n + 1):
	miku[i] += miku[i - 1] + ord(s[i - 1]) - 96
for i in range(q):
	(l, r) = map(int, input().split())
	print(solve(l, r))


a = ord('a') - 1
(n, q) = [int(x) for x in input().split()]
s = input()
dp = [0 for _ in range(n + 1)]
for i in range(n):
	dp[i + 1] = dp[i] + ord(s[i]) - a
for i in range(q):
	(l, r) = [int(x) for x in input().split()]
	print(dp[r] - dp[l - 1])


(n, q) = map(int, input().split())
s = input()
arr = [0] * (n + 1)
arr[1] = ord(s[0]) - 96
for i in range(2, n + 1):
	arr[i] += ord(s[i - 1]) - 96 + arr[i - 1]
for _ in range(q):
	(a, b) = map(int, input().split())
	if a == 1:
		print(arr[b])
	else:
		print(arr[b] - arr[a - 1])


from itertools import accumulate
(n, q) = map(int, input().split())
s = input()
p = [0]
p.extend(accumulate((ord(c) - ord('a') + 1 for c in s)))
for _ in range(q):
	(l, r) = map(int, input().split())
	print(p[r] - p[l - 1])


int_inp = lambda : int(input())
strng = lambda : input().strip()
strl = lambda : list(input().strip())
mul = lambda : map(int, input().split())
mulf = lambda : map(float, input().split())
seq = lambda : list(map(int, input().split()))
import math
from collections import Counter, defaultdict
d = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
(c, b) = mul()
k = input()
a = []
summ = 0
a.append(0)
for i in k:
	a.append(summ + d[i])
	summ = summ + d[i]
for i in range(b):
	(m, n) = mul()
	print(a[n] - a[m - 1])


import sys
import math
from math import gcd
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)
N = 20005
T = 1
alp = 'abcdefghijklmnopqrstuvwxyz'
for _ in range(T):
	(n, q) = list(map(int, stdin.readline().rstrip().split()))
	s = str(stdin.readline().strip('\n'))
	d = {}
	for i in range(26):
		d[alp[i]] = i + 1
	a = [0] * n
	for i in range(n):
		a[i] = d[s[i]]
	p = [0] * n
	p[0] = a[0]
	for i in range(n):
		if i != 0:
			p[i] = p[i - 1] + a[i]
	p = [0] + p
	for i in range(q):
		(l, r) = list(map(int, stdin.readline().rstrip().split()))
		print(p[r] - p[l - 1])