local q = io.read("*n", "*l") for iq = 1, q do local n = io.read("*n", "*l") local s = io.read() local t = {} for i = 1, n do local b = s:byte(i) - 64 table.insert(t, b) while true do if 2 < #t and t[#t - 1] == 2 and t[#t - 2] == 1 and t[#t] == 2 then table.remove(t) table.remove(t) table.remove(t) table.insert(t, 2) else break end end end for i = 1, #t do t[i] = string.char(t[i] + 64) end print(table.concat(t)) end