N, Q = gets.split.map(&:to_i) S = gets.chomp counter = Array.new(N + 1) { Array.new(26, 0) } N.times do |i| v = S[i].ord - 'a'.ord 26.times do |j| counter[i + 1][j] = counter[i][j] end counter[i + 1][v] += 1 end v = Array.new(26, 0) Q.times do l, r, x = gets.split.map(&:to_i) 26.times do |i| v[i] = counter[r][i] - counter[l - 1][i] end 1.upto(25) do |i| v[i] += v[i - 1] end idx = v.bsearch_index { |c| c >= x } puts (idx + 97).chr end