import java.util.ArrayDeque; import java.util.Deque; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int x = 0; x < t; x++){ int n = sc.nextInt(); String s = sc.next(); Deque q = new ArrayDeque<>(); for(int i = n - 1; i >= 0; i--){ q.addFirst(s.substring(i, i + 1)); if(q.size() >= 3){ String a1 = q.pollFirst(); String a2 = q.pollFirst(); String a3 = q.pollFirst(); if(a1.equals("A") && a2.equals("B") && a3.equals("B")){q.addFirst(a3);} else{ q.addFirst(a3); q.addFirst(a2); q.addFirst(a1); } } } System.out.println(String.join("", q)); } } }