import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        
        while(t-- > 0) {
            String s = br.readLine();
            long gcd = 0;
            String[] arr = s.split(" ");
            for(int i=1; i<arr.length-1; i++) {
                for(int j=i+1; j<arr.length; j++) {
                    gcd += gcd(Integer.parseInt(arr[i]), Integer.parseInt(arr[j]));
                }
            }
            
            System.out.println(gcd);
        }
    }
    
    public static int gcd(int n1, int n2) {
        if(n2 == 0) { return n1; }
        
        return gcd(n2, n1%n2);
    }
}