#![allow(non_snake_case, unused_must_use, unused_imports)] use std::io::{self, prelude::*}; fn main() { let (stdin, stdout) = (io::read_to_string(io::stdin()).unwrap(), io::stdout()); let (mut stdin, mut buffer) = (stdin.split_whitespace(), io::BufWriter::new(stdout.lock())); macro_rules! input { ($t: ty, $n: expr) => { (0..$n).map(|_| input!($t)).collect::>() }; ($t: ty) => { stdin.next().unwrap().parse::<$t>().unwrap() }; } let N = input!(usize); let S = input!(String); let T = input!(String); let A = input!(usize, N); let mut dp = vec![isize::MIN; 200_010]; dp[0] = 0; for i in 0..200_010 { if i + S.len() < 200_010 { dp[i + S.len()] = std::cmp::max(dp[i + S.len()], dp[i] + 1); } if i + T.len() < 200_010 { dp[i + T.len()] = std::cmp::max(dp[i + T.len()], dp[i]); } } for a in A { let mut ans = vec![]; for _ in 0..dp[a] { ans.push(S.clone()); } let t = (a - S.len() * dp[a] as usize) / T.len(); for _ in 0..t { ans.push(T.clone()); } writeln!( buffer, "{}", ans.iter() .map(|x| x.to_string()) .collect::>() .join(" ") ); } }