fn run<'a, I, W>(mut scanner: I, mut writer: W) where I: Iterator, W: std::io::Write, { macro_rules! scan { ([$t:tt; $n:expr]) => ((0..$n).map(|_| scan!($t)).collect::>()); (($($t:tt),*)) => (($(scan!($t)),*)); (Usize1) => (scan!(usize) - 1); (Bytes) => (scan!(String).into_bytes()); ($t:ty) => (scanner.next().unwrap().parse::<$t>().unwrap()); } macro_rules! input { ($($($v:ident)* : $t:tt),* $(,)?) => ($(let $($v)* = scan!($t);)*); } input! { n: usize, q: usize, s: Bytes, } let mut sum = vec![vec![0; n + 1]; 26]; for (i, s) in s.into_iter().enumerate() { sum[(s - b'a') as usize][i + 1] += 1; } for sum in sum.iter_mut() { for i in 0..n { sum[i + 1] += sum[i]; } } for _ in 0..q { input! { l: Usize1, r: usize, mut x: usize, } for (i, sum) in sum.iter().enumerate() { let sum = sum[r] - sum[l]; if sum < x { x -= sum; } else { writer.write_all(&[b'a' + i as u8]).ok(); writer.write_all(b"\n").ok(); break; } } } } fn main() { let ref mut buf = Vec::new(); std::io::Read::read_to_end(&mut std::io::stdin(), buf).ok(); let scanner = unsafe { std::str::from_utf8_unchecked(buf).split_ascii_whitespace() }; let stdout = std::io::stdout(); let writer = std::io::BufWriter::new(stdout.lock()); run(scanner, writer); }