#include <bits/stdc++.h>

using namespace std;

template <class T> inline void read(T &x) {
    int f = 0; x = 0; char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) f |= (ch == '-');
    for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
    if (f) x = -x;
}

typedef long long ll;

const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int N = 2e5 + 7;

int  a[N], num[N], dp[N], n;

void solve() {
    read(n);
    memset(num, 0, sizeof(num));
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= n; ++i) {
        read(a[i]);
        num[a[i]]++;
        dp[a[i]]++;
    }

    for (int i = 1; i <= 200000; ++i) {
        if (!num[i]) continue;
        for (int j = i + i; j <= 200000; j += i) {
            if (!num[j]) continue;
            dp[j] = max(dp[j], dp[i] + num[j]);
        }
    }

    int ans = n - 1;
    for (int i = 1; i <= n; ++i) {
        ans = min(ans, n - dp[ a[i] ]);
    }
    
    printf("%d\n", ans);
}

int main() {
    int _T = 1;
    read(_T);
    while (_T--) solve();
}
  	  	  	   	  	 	 	   		 	 		