#![allow(non_snake_case, unused_imports)] use std::cmp::Reverse; use std::collections::{BinaryHeap, HashMap, HashSet}; use proconio::{input, marker::Usize1, marker::Chars}; use itertools::Itertools; #[allow(unused_macros)] macro_rules! d { ( $( $x:expr ),* $(,)? ) => { eprintln!( concat!( $( stringify!($x), "={:?} " ),* ), $( $x ),* ); }; } #[allow(dead_code)] fn yn(b: bool) -> &'static str { if b { "Yes" } else { "No" } } fn solve() -> String { input! { R: String, S: String, K: usize, } if S == "NotWarong" { if R.chars().take(K).all(|c| c == 'A') { let mut s = String::new(); for c in R.chars() { if c == '?' { s.push('A') } else { s.push(c) } } return s } let freq = R.chars().counts(); let qcnt = *freq.get(&'?').unwrap_or(&0); let wcnt = *freq.get(&'W').unwrap_or(&0); let hd_qcnt = R.chars() .take(K) .filter(|&c| c == '?') .count(); if wcnt == 0 && hd_qcnt == 1 && qcnt == 1 { let r = R.replace('?', "W"); return r } return R; } let freq = R.chars().skip(K as usize).counts(); let qcnt = *freq.get(&'?').unwrap_or(&0); let wcnt = *freq.get(&'W').unwrap_or(&0); let mut s = String::new(); for _ in 0..K { s.push('A'); } let cs: Vec = R.chars().collect(); for i in K as usize..R.len() { if cs[i] == '?' && qcnt == 1 && wcnt == 0 { s.push('W'); } else { s.push(cs[i]); } } s } fn main() { input! { T: usize, } for _ in 0..T { let ans = solve(); println!("{}", ans); } }