#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
int f[maxn], a[maxn], id[maxn];
signed main()
{
	int t; cin >> t;
	while (t--)
	{
		int n, ans = 0; cin >> n;
		for (int i = 1; i <= n; i++)	scanf("%d", &a[i]);
		sort(a + 1, a + 1 + n);
		for (int i = 1; i <= n; i++)
		{
			f[i] = 1;
			for (int j = 1; j * j <= a[i]; j++)
			{
				if (a[i] % j != 0)	continue;
				int last = a[i] / j;
				f[i] = max(f[i], f[id[j]] + 1);
				f[i] = max(f[i], f[id[last]] + 1);
			}
			id[a[i]] = i;
			ans = max(ans, f[i]);
		}
		printf("%d\n", n - ans);
		for (int i = 1; i <= 200000; i++)	f[i] = id[i] = 0;
	}
}