





#include
<iostream>
#include
<iomanip>
#include<algorithm>
using
namespace
std;
int
main()
{
long
long
zhanzhuan(
long
long
,
long
long
);
int
N;
cin >> N;
while
(N--)
{
int
i,
j;
long
long
a[1002], n,t=0,b;
cin
>> n;
t
= 0;
for
(i
= 1; i <= n; i++)
{
cin
>> a[i];
}
if
(n
== 1)
{cout
<<
'0'
<<
endl;
continue
;
}
for
(i
= 1; i <= n; i++)
{
for
(j
= i; j <= n; j++)
{
b=
zhanzhuan(a[i], a[j]);
t
= t + a[i] * a[j] /b-b;
}
}
t
= t * 2;
cout
<< t<< endl;
}
return
0;
}
long
long
zhanzhuan(
long
long
x,
long
long
y)
{
long
long
r = 1;
if
(x
> y)swap(x, y);
while
(r
!= 0)
{
r
= x%y;
x
= y;
y
= r;
}
return
x;
}