using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
//using static CompLib.CompLib;
//using DataStructure;

namespace atcoder
{
    class Program
    {
        const int intMax = 1000000000;
        const long longMax = 2000000000000000000;
        static void Main(string[] args)
        {
            int T = int.Parse(Console.ReadLine());
            while (T-- > 0)
            {
                int N = int.Parse(Console.ReadLine());
                String S = Console.ReadLine();
                var stack = new Stack<char>();
                for (int i = S.Length - 1; i >= 0; i--)
                {
                    stack.Push(S[i]);
                    if (stack.Count > 2)
                    {
                        if (stack.ElementAt(1) == 'B' && stack.ElementAt(0) == 'A' && stack.ElementAt(2) == 'B')
                        {
                            stack.Pop();
                            stack.Pop();
                        }
                    }
                }
                String ans = "";
                while (stack.Count > 0)
                {
                    ans += stack.Pop();
                }
                Console.WriteLine(ans);
            }
        }
    }
}