#[macro_export] macro_rules! setup { { mut $input:ident: SplitWhitespace $(,)? } => { use std::io::Read; let mut buf = String::new(); std::io::stdin().read_to_string(&mut buf).ok(); let mut $input = buf.split_whitespace(); }; } #[macro_export] macro_rules! parse_next { ($str_iter:expr) => { $str_iter.next().unwrap().parse().ok().unwrap() }; } #[allow(unused_imports)] use std::collections::{HashMap, HashSet, VecDeque}; fn main() { setup! { mut input: SplitWhitespace }; let _n: usize = parse_next!(input); let q: usize = parse_next!(input); let s: String = parse_next!(input); let mut l: Vec = vec![]; let mut r: Vec = vec![]; let mut x: Vec = vec![]; (0..q).for_each(|_| { l.push(parse_next!(input)); r.push(parse_next!(input)); x.push(parse_next!(input)); }); let mut char_count = vec![]; { char_count.push(vec![0; 26]); } for (i, c) in s.chars().enumerate() { let mut v = char_count[i].clone(); v[(c as u8 - 'a' as u8) as usize] += 1; char_count.push(v); } for i in 0..q { let left = char_count[l[i] - 1].clone(); let right = char_count[r[i]].clone(); let mut char_count_lr = right; for j in 0..26 { char_count_lr[j] -= left[j]; } let ans = (|| { let mut count = 0; for j in 0..26 { count += char_count_lr[j]; if x[i] <= count { return ('a' as u8 + j as u8) as char; } } unreachable!(); })(); println!("{}", ans); } }