fn solve() -> String { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let mut s = s.trim().chars().collect::>(); let mut bcnt = 0usize; let mut stack = vec![]; for _ in 0..n { let val = s.pop().unwrap(); if val == 'B' { stack.push(val); bcnt += 1; } else { if bcnt > 1 && stack[stack.len()-1] == 'B' && stack[stack.len()-2] == 'B' { stack.pop(); bcnt -= 1; } else { stack.push(val); } } } let stack = stack.into_iter().rev().map(|c| c.to_string()).collect::>(); stack.join("") } fn main() { let mut t = String::new(); std::io::stdin().read_line(&mut t).ok(); let t: usize = t.trim().parse().unwrap(); let mut result = Vec::with_capacity(t); for _ in 0..t { result.push(solve()); } for v in result.iter() { println!("{}", v); } }