let input = require('fs').readFileSync('/dev/stdin').toString().trim().split('\n');
const N = +input.shift();
const getGCD = (a, b) => {
if (a % b === 0) return b;
return getGCD(b, a % b);
};
const sol = (arr) => {
let n = arr.shift();
let sum = 0;
arr.sort((a, b) => b - a);
arr.forEach((e, i) => {
while (i < arr.length - 1) {
sum += getGCD(e, arr[++i]);
}
});
return sum;
};
input.forEach((e) => {
console.log(sol(e.split(" ").map(Number)));
});