N, Q = map(int, input().split()) S = input() alpha =['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'] data = ['' for _ in range(int(N*(N+1)/2))] for i in range(N): for j in range(i,N): for k in range(26): c = S.count(alpha[k], i, j+1) data[int(N*i+j-i*(i+1)/2)] += alpha[k]*c L = [] Y = [[] for _ in range(Q)] for i in range(Q): L.append(list(map(int, input().split()))) for i in list(set([p[0] for p in L])): a = [[j, x] for j, x in enumerate(L) if x[0] == i] for k in list(set([q[1][1] for q in a])): b = [[y[1][2], y] for y in a if y[1][1] == k] for l in list(set([r[0] for r in b])): for m in b: if l==m[0]: Y[m[1][0]] = data[int(N*(i-1)+j-1-i*(i-1)/2)][l-1] for i in range(Q): print(Y[i])