#include<bits/stdc++.h>
// #pragma GCC optimize("unroll-loops" , "O3")
// #pragma GCC target("avx2")
using namespace std;
#define int long long
void run_case()
{
int n ;
cin>>n;
vector<int> occ(n + 1);
vector<int> a(n);
vector<int> f(n + 1);
for(int i = 0 ; i < n ; i++)
{
cin>>a[i];
occ[a[i]]++;
}
int ans = n;
for(int i = 1 ; i <= n; i++)
{
for(int j = 2 * i ;j <= n ; j+=i)
{
f[i]+=occ[j];
f[j]+=occ[i];
}
ans = min(ans , f[i] + (n - f[i] - occ[i]) * 2);
}
cout<<ans<<'\n';
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin>>t;
while (t--)
{
run_case();
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KLy8gI3ByYWdtYSBHQ0Mgb3B0aW1pemUoInVucm9sbC1sb29wcyIgLCAiTzMiKQovLyAjcHJhZ21hIEdDQyB0YXJnZXQoImF2eDIiKQp1c2luZyBuYW1lc3BhY2Ugc3RkOwojZGVmaW5lIGludCBsb25nIGxvbmcKdm9pZCBydW5fY2FzZSgpCnsKICAgIGludCBuIDsKICAgIGNpbj4+bjsKICAgIHZlY3RvcjxpbnQ+IG9jYyhuICsgMSk7CiAgICB2ZWN0b3I8aW50PiBhKG4pOwogICAgdmVjdG9yPGludD4gZihuICsgMSk7CiAgICBmb3IoaW50IGkgPSAwIDsgaSA8IG4gOyBpKyspCiAgICB7CiAgICAgICAgY2luPj5hW2ldOwogICAgICAgIG9jY1thW2ldXSsrOwogICAgfQogICAgaW50IGFucyA9IG47CiAgICBmb3IoaW50IGkgPSAxIDsgaSA8PSBuOyAgaSsrKQogICAgewogICAgICAgIGZvcihpbnQgaiA9IDIgKiBpIDtqIDw9IG4gOyBqKz1pKQogICAgICAgIHsKICAgICAgICAgICAgZltpXSs9b2NjW2pdOwogICAgICAgICAgICBmW2pdKz1vY2NbaV07CiAgICAgICAgfQogICAgICAgIGFucyA9IG1pbihhbnMgLCBmW2ldICsgKG4gLSBmW2ldIC0gb2NjW2ldKSAqIDIpOwogICAgfQogICAgY291dDw8YW5zPDwnXG4nOwp9CnNpZ25lZCBtYWluKCkKewogICAgaW9zOjpzeW5jX3dpdGhfc3RkaW8oMCk7CiAgICBjaW4udGllKDApOwogICAgY291dC50aWUoMCk7CiAgICBpbnQgdCA9IDE7CiAgICBjaW4+PnQ7CiAgICB3aGlsZSAodC0tKQogICAgewogICAgICAgIHJ1bl9jYXNlKCk7CiAgICB9CiAgICAKfQ==