#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>

#define lc u << 1
#define rc u << 1 | 1

using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N = 200010;
int c[N];
int f[N],a[N];
int n;

void solve()
{
    scanf("%d",&n);
    for(int i = 1;i <= n;i ++)
    {
        scanf("%d",&a[i]);
        c[a[i]] ++;
    }
    for(int i = 1;i < N;i ++)
        if(c[i])
        {
            f[i] += c[i];
            for(int j = i * 2;j < N;j += i)
                f[j] = max(f[j],f[i]);
        }
    printf("%d\n",(n - *max_element(f,f + N)));
    memset(c,0,sizeof c);
    memset(f,0,sizeof f);
}

int main()
{
    #ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #else
    #endif // LOCAL
    // init(N - 1);
    int T = 1;
    scanf("%d",&T);
    while(T --)
    {
        // scanf("%lld%lld",&n,&m);
        solve();
        // test();
    }
    return 0;
}