package no3165_croissants_continu; import java.util.*; public class Main { public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); StringBuilder sb = new StringBuilder(); for(int i = 0;i < t;i++) { int n = Integer.parseInt(sc.next()); PriorityQueue q = new PriorityQueue<>(Collections.reverseOrder()); for(int j = 0;j < n;j++) { q.add(sc.nextInt()); }long ans = 0; while(q.size() > 1) { int a = q.poll(); int b = q.poll(); ans += b * 2L; if(a != b) { q.add(a - b); } }if(q.size() == 1)ans++; sb.append(ans + "\n"); }System.out.print(sb); } }