#include <iostream>
using namespace std;
int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a%b);
}
int main() {
int n, m, sum;
cin >> n;
while(n-- > 0) {
cin >> m;
int ns[m];
for(int i = 0; i < m; i++) cin >> ns[i];
sum = 0;
for(int i = 0; i < m; i++) {
for(int j = i + 1; j < m; j++) sum += gcd(ns[i], ns[j]);
}
cout << sum << endl;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IGdjZChpbnQgYSwgaW50IGIpIHsKICAgIHJldHVybiBiID09IDAgPyBhIDogZ2NkKGIsIGElYik7CiAgfQoKaW50IG1haW4oKSB7CglpbnQgbiwgbSwgc3VtOwoJY2luID4+IG47Cgl3aGlsZShuLS0gPiAwKSB7CgkJY2luID4+IG07IAogICAgICAgIGludCBuc1ttXTsKICAgICAgICBmb3IoaW50IGkgPSAwOyBpIDwgbTsgaSsrKSBjaW4gPj4gbnNbaV07CiAgICAgICAgc3VtID0gMDsKICAgICAgICBmb3IoaW50IGkgPSAwOyBpIDwgbTsgaSsrKSB7CiAgICAgICAgICAgIGZvcihpbnQgaiA9IGkgKyAxOyBqIDwgbTsgaisrKSBzdW0gKz0gZ2NkKG5zW2ldLCBuc1tqXSk7CiAgICAgICAgfQogICAgICAgIGNvdXQgPDwgc3VtIDw8IGVuZGw7CiAgICB9Cn0=