#include<bits/stdc++.h>
#define ll long long
#define boost1 ios_base::sync_with_stdio(false);
#define boost2 cin.tie(0);cout.tie(0);
using namespace std;

int main()
{
    boost1 boost2
    int t;cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        int  p  = n*m;
        char A[p+1];
        for(int i=1;i<=p;i++) cin>>A[i];
        int j=1;
        int row[n+1]={0};
        int column[m+1]={0};
        for(int i=1;i<=p;i++)
        {
            if(A[i]=='.') row[j]+=1;
            if(i%m==0) j++;
        }
        int min_row = *min_element(row+1,row+n+1);
        int ans = min_row;
        int index;
        for(int i=1;i<=n;i++)
        {
            if(row[i]==min_row) index = i;
        }
        for(int i = (n*index)+1-n;i<(n*index)+1;i++)
        {
            A[i]='*';
        }
        for(int i=1;i<=p;i++)
        {
            if(A[i]=='.'){
                    int q = i%m;
                    if(q==0) q=m;
                column[q]+=1;
            }
        }
        ans += *min_element(column+1,column+m+1);
        cout<<ans<<"\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
int main()
{
	int q,m,n;cin >> q;
	for(int x=0;x<q;x++)
	{
		cin >> n >> m;
		char arr[n][m];
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
				cin >> arr[i][j];
		}
		int ans[m][n],C,R,max=-1,c[m],r[n];
		for(int i=0;i<m;i++) c[i] = 0;
		for(int i=0;i<n;i++) r[i] = 0;

		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(arr[i][j] == '*')
					r[i] ++;
			}
		}

		for(int i=0;i<m;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(arr[j][i] == '*')
					c[i] ++;
			}
		}
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
				ans[i][j] = r[i]+c[j];
		}
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(ans[i][j] > max)
					max = ans[i][j];
			}
		}
		if(max < 0) cout << 0 << endl;
		else cout << n+m-max << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
int main()
{
	int q,m,n;cin >> q;
	for(int x=0;x<q;x++)
	{
		cin >> n >> m;
		char arr[n][m];
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
				cin >> arr[i][j];
		}
		int ans[m][n],C,R,maxi=-1,c[m],r[n];
		for(int i=0;i<m;i++) c[i] = 0;
		for(int i=0;i<n;i++) r[i] = 0;

		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(arr[i][j] == '*')
					r[i] ++;
			}
		}

		for(int i=0;i<m;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(arr[j][i] == '*')
					c[i] ++;
			}
		}
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				// if(arr[i][j] == '.')
					ans[i][j] = r[i]+c[j];
				// else
				// 	ans[i][j] = r[i]+c[j];
			}
		}
		// for(int i=0;i<n;i++){
		// 	for(int j=0;j<m;j++)
		// 		cout << ans[i][j] << " ";
		// 	cout << endl;
		// }
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(ans[i][j] >= maxi){
					if(arr[i][j] == '.')
						maxi = ans[i][j]+1;
					else
						maxi = ans[i][j];

				}
			}
		}
		if(maxi < 0) cout << 0 << endl;
		else{
			cout << n+m-maxi << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
int main()
{
	int q,m,n;cin >> q;
	for(int x=0;x<q;x++)
	{
		cin >> n >> m;
		char arr[n][m];
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
				cin >> arr[i][j];
		}
		int ans[m][n],C,R,maxi=-1,c[m],r[n];
		for(int i=0;i<m;i++) c[i] = 0;
		for(int i=0;i<n;i++) r[i] = 0;

		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(arr[i][j] == '*')
					r[i] ++;
			}
		}

		for(int i=0;i<m;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(arr[j][i] == '*')
					c[i] ++;
			}
		}
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(arr[i][j] == '.')
					ans[i][j] = r[i]+c[j]+1;
				else
					ans[i][j] = r[i]+c[j];
			}
		}
		// for(int i=0;i<n;i++){
		// 	for(int j=0;j<m;j++)
		// 		cout << ans[i][j] << " ";
		// 	cout << endl;
		// }
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(ans[i][j] > maxi){
					maxi = ans[i][j];
					R=i;C=j;
				}
			}
		}
		if(maxi < 0) cout << 0 << endl;
		else{
			cout << n+m-maxi << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
int main()
{
	int q,m,n;cin >> q;
	for(int x=0;x<q;x++)
	{
		cin >> n >> m;
		char arr[n][m];
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
				cin >> arr[i][j];
		}
		int ans[m][n],C,R,max=-1,c[m],r[n];
		for(int i=0;i<m;i++) c[i] = 0;
		for(int i=0;i<n;i++) r[i] = 0;

		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(arr[i][j] == '*')
					r[i] ++;
			}
		}

		for(int i=0;i<m;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(arr[j][i] == '*')
					c[i] ++;
			}
		}
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
				ans[i][j] = r[i]+c[j];
		}
		// for(int i=0;i<n;i++){
		// 	for(int j=0;j<m;j++)
		// 		cout << ans[i][j] << " ";
		// 	cout << endl;
		// }
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(ans[i][j] > max){
					max = ans[i][j];
					R=i;C=j;
				}
			}
		}
		if(max < 0) cout << 0 << endl;
		else{
			if(arr[R][C] == '*')
				cout << n+m-max << endl;
			else
				cout << n+m-max-1 << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
int main()
{
	int q,m,n;cin >> q;
	for(int x=0;x<q;x++)
	{
		cin >> n >> m;
		char arr[n][m];
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
				cin >> arr[i][j];
		}
		int ans[m][n],C,R,maxi=-1,c[m],r[n];
		for(int i=0;i<m;i++) c[i] = 0;
		for(int i=0;i<n;i++) r[i] = 0;

		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(arr[i][j] == '*')
					r[i] ++;
			}
		}

		for(int i=0;i<m;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(arr[j][i] == '*')
					c[i] ++;
			}
		}
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
				ans[i][j] = r[i]+c[j];
		}
		// for(int i=0;i<n;i++){
		// 	for(int j=0;j<m;j++)
		// 		cout << ans[i][j] << " ";
		// 	cout << endl;
		// }
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(ans[i][j] > maxi){
					maxi = ans[i][j];
					R=i;C=j;
				}
			}
		}
		if(maxi < 0) cout << 0 << endl;
		else{
			if(arr[R][C] == '*')
				cout << n+m-maxi << endl;
			else
				cout << n+m-maxi-1 << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
int main()
{
	int q,m,n;cin >> q;
	for(int x=0;x<q;x++)
	{
		cin >> n >> m;
		char arr[n][m];
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
				cin >> arr[i][j];
		}
		int ans,C,R,maxC=-1,maxR=-1,c[m],r[n];
		for(int i=0;i<m;i++) c[i] = 0;
		for(int i=0;i<n;i++) r[i] = 0;

		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(arr[i][j] == '*')
					r[i] ++;
			}
		}

		for(int i=0;i<m;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(arr[j][i] == '*')
					c[i] ++;
			}
		}
		for(int i=0;i<n;i++)
		{
			if(r[i] > maxR) {
				maxR = r[i];
				R = i;
			}
		}

		for(int i=0;i<m;i++)
		{
			if(c[i] > maxC) {
				maxC = c[i];
				C = i;
			}
		}

		if(arr[R][C] == '.')
			ans =  m + n - maxC - maxR - 1 ;
		else
			ans =  m + n - maxC - maxR ;

		if(ans < 0)
			cout << 0 << endl;
		else
			cout << ans << endl;

	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
int main()
{
	int q,m,n;cin >> q;
	for(int x=0;x<q;x++)
	{
		cin >> n >> m;
		char arr[n][m];
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
				cin >> arr[i][j];
		}
		int ans=-1,maxR=-1,maxC=-1,c[m],r[n];
		vector<int> C,R;
		for(int i=0;i<m;i++) c[i] = 0;
		for(int i=0;i<n;i++) r[i] = 0;

		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(arr[i][j] == '*')
					r[i] ++;
			}
		}

		for(int i=0;i<m;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(arr[j][i] == '*')
					c[i] ++;
			}
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				int tmp = r[i]+c[j];
				if(arr[i][j] == '.')
					tmp ++;
				ans = max(ans,tmp);
			}
		}
		cout << n+m-ans << endl;

	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
int main()
{
	int q,m,n;cin >> q;
	for(int x=0;x<q;x++)
	{
		cin >> n >> m;
		char arr[n][m];
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
				cin >> arr[i][j];
		}
		int ans[m][n],C,R,maxi=-1,c[m],r[n];
		for(int i=0;i<m;i++) c[i] = 0;
		for(int i=0;i<n;i++) r[i] = 0;

		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(arr[i][j] == '*')
					r[i] ++;
			}
		}

		for(int i=0;i<m;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(arr[j][i] == '*')
					c[i] ++;
			}
		}
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(arr[i][j] == '.')
					ans[i][j] = r[i]+c[j];
				else
					ans[i][j] = r[i]+c[j];
			}
		}
		// for(int i=0;i<n;i++){
		// 	for(int j=0;j<m;j++)
		// 		cout << ans[i][j] << " ";
		// 	cout << endl;
		// }
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(ans[i][j] >= maxi){
					if(arr[i][j] == '.')
						maxi = ans[i][j]+1;
					else
						maxi = ans[i][j];

				}
			}
		}
		if(maxi < 0) cout << 0 << endl;
		else{
			cout << n+m-maxi << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 2010;
const long long mod = 998244353;

using namespace std;

int n,m;
char a[N][N];
bool used[N][N];

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        cin>>n;
        for( int i=1; i<=n; i++ ){
                int x,y;
                cin>>x>>y;
                for( int j=1; j<=x; j++ ){
                        for( int h=1; h<=y; h++ ){
                                cin>>a[j][h];
                        }
                }
                vector<int>s,d;
                int k;
                int cnt = 0;
                for( int j=1; j<=x; j++ ){
                        k = 0;
                        s.clear();
                        for( int h=1; h<=y; h++ ){
                                if( a[j][h] == '*' )k++;
                                s.push_back(j);
                                s.push_back(h);
                        }
                        cnt = max(cnt,k);
                }
                for( int j=1; j<=x; j++ ){
                        s.clear();
                        for( int h=1; h<=y; h++ ){
                                if( a[j][h] == '*' )k++;
                                s.push_back(j);
                                s.push_back(h);
                        }
                        if( k == cnt ){
                                for( int k = 0; k < s.size(); k++ ){
                                        used[s[k]][s[k+1]] = true;
                                        d.push_back(s[k]);
                                        d.push_back(s[k+1]);
                                }
                        }
                }
                int ans = 0;
                for( int j=1; j<=y; j++ ){
                        k = 0;
                        for( int h=1; h<=x; h++ ){
                                if( a[h][j] == '*' )k++;
                                else{
                                        if( used[h][j] )k++;
                                }
                        }
                        ans = max(ans,k);
                }
                for( int j=0; j<d.size(); j+=2 ){
                        used[d[j]][d[j+1]] = false;
                }
                cout<< ( y - cnt ) + ( x - ans ) << endl;
        }
}


#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 2000010;
const long long mod = 998244353;

using namespace std;

int n,m;
vector< vector< bool > > used;
vector< vector< char > > a;
int k1[N],k11[N];

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        cin>>n;
        for( int i=1; i<=n; i++ ){
                int x,y;
                cin>>x>>y;
                a.clear();
                used.clear();
                a.resize(x + 2);
                used.resize(x + 2);
                for(int i = 0; i <= x + 1; i++){
                        for(int j = 0; j <= y + 1; j++){
                                a[i].push_back(0);
                                used[i].push_back(false);
                        }
                }
                for( int j=1; j<=x; j++ ){
                        for( int h=1; h<=y; h++ ){
                                cin>>a[j][h];
                        }
                }
                vector<int>s,d;
                int k;
                int cnt = 0;
                for( int j=1; j<=x; j++ ){
                        k = 0;
                        for( int h=1; h<=y; h++ ){
                                if( a[j][h] == '*' )k++;
                        }
                        k1[j] = k;
                        cnt = max(cnt,k);
                }
                for( int j=1; j<=y; j++ ){
                        k = 0;
                        for( int h=1; h<=x; h++ ){
                                if( a[h][j] == '*' )k++;
                        }
                        k11[j] = k;
                }
                int ans = x+y;
                for( int j=1; j<=x; j++ ){
                        for( int h=1; h<=y; h++ ){
                           ans = min( ans , ( y - k1[j] ) + ( x - k11[h] ) - (a[j][h] == '.') );
                        }
                }
                cout<<ans<<endl;
        }
}


#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 40010;
const long long mod = 998244353;

using namespace std;

int n,m;
char a[N][N];
bool used[N][N];

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        cin>>n;
        for( int i=1; i<=n; i++ ){
                int x,y;
                cin>>x>>y;
                for( int j=1; j<=x; j++ ){
                        for( int h=1; h<=y; h++ ){
                                cin>>a[j][h];
                        }
                }
                vector<int>s,d;
                int k;
                int cnt = 0;
                for( int j=1; j<=x; j++ ){
                        k = 0;
                        s.clear();
                        for( int h=1; h<=y; h++ ){
                                if( a[j][h] == '*' )k++;
                                s.push_back(j);
                                s.push_back(h);
                        }
                        cnt = max(cnt,k);
                }
                for( int j=1; j<=x; j++ ){
                        s.clear();
                        for( int h=1; h<=y; h++ ){
                                if( a[j][h] == '*' )k++;
                                s.push_back(j);
                                s.push_back(h);
                        }
                        if( k == cnt ){
                                for( int k = 0; k < s.size(); k++ ){
                                        used[s[k]][s[k+1]] = true;
                                        d.push_back(s[k]);
                                        d.push_back(s[k+1]);
                                }
                        }
                }
                int ans = 0;
                for( int j=1; j<=y; j++ ){
                        k = 0;
                        for( int h=1; h<=x; h++ ){
                                if( a[h][j] == '*' )k++;
                                else{
                                        if( used[h][j] )k++;
                                }
                        }
                        ans = max(ans,k);
                }
                for( int j=0; j<d.size(); j+=2 ){
                        used[d[j]][d[j+1]] = false;
                }
                cout<< ( y - cnt ) + ( x - ans ) << endl;
        }
}


#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 30010;
const long long mod = 998244353;

using namespace std;

int n,m;
char a[N][N];
bool used[N][N];

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        cin>>n;
        for( int i=1; i<=n; i++ ){
                int x,y;
                cin>>x>>y;
                for( int j=1; j<=x; j++ ){
                        for( int h=1; h<=y; h++ ){
                                cin>>a[j][h];
                        }
                }
                vector<int>s,d;
                int k;
                int cnt = 0;
                for( int j=1; j<=x; j++ ){
                        k = 0;
                        s.clear();
                        for( int h=1; h<=y; h++ ){
                                if( a[j][h] == '*' )k++;
                                s.push_back(j);
                                s.push_back(h);
                        }
                        cnt = max(cnt,k);
                }
                for( int j=1; j<=x; j++ ){
                        s.clear();
                        for( int h=1; h<=y; h++ ){
                                if( a[j][h] == '*' )k++;
                                s.push_back(j);
                                s.push_back(h);
                        }
                        if( k == cnt ){
                                for( int k = 0; k < s.size(); k++ ){
                                        used[s[k]][s[k+1]] = true;
                                        d.push_back(s[k]);
                                        d.push_back(s[k+1]);
                                }
                        }
                }
                int ans = 0;
                for( int j=1; j<=y; j++ ){
                        k = 0;
                        for( int h=1; h<=x; h++ ){
                                if( a[h][j] == '*' )k++;
                                else{
                                        if( used[h][j] )k++;
                                }
                        }
                        ans = max(ans,k);
                }
                for( int j=0; j<d.size(); j+=2 ){
                        used[d[j]][d[j+1]] = false;
                }
                cout<< ( y - cnt ) + ( x - ans ) << endl;
        }
}


#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 2010;
const long long mod = 998244353;

using namespace std;

int n,m;
char a[N][N];
bool used[N][N];

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        cin>>n;
        for( int i=1; i<=n; i++ ){
                int x,y;
                cin>>x>>y;
                for( int j=1; j<=x; j++ ){
                        for( int h=1; h<=y; h++ ){
                                cin>>a[j][h];
                        }
                }
                vector<int>s,d;
                int k;
                int cnt = 0;
                for( int j=1; j<=x; j++ ){
                        k = 0;
                        s.clear();
                        for( int h=1; h<=y; h++ ){
                                if( a[j][h] == '*' )k++;
                                s.push_back(j);
                                s.push_back(h);
                        }
                        if( k > cnt ){
                                cnt = k;
                                d = s;
                        }
                }
                for( int j=0; j<d.size(); j+=2 ){
                        used[d[j]][d[j+1]] = true;
                }
                int ans = 0;
                for( int j=1; j<=y; j++ ){
                        k = 0;
                        for( int h=1; h<=x; h++ ){
                                if( a[h][j] == '*' )k++;
                                else{
                                        if( used[h][j] )k++;
                                }
                        }
                        ans = max(ans,k);
                }
                for( int j=0; j<d.size(); j+=2 ){
                        used[d[j]][d[j+1]] = false;
                }
                cout<< ( y - cnt ) + ( x - ans ) << endl;
        }
}


#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 60100;
const long long mod = 998244353;

using namespace std;

int n,m;
char a[N][N];
bool used[N][N];

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        cin>>n;
        for( int i=1; i<=n; i++ ){
                int x,y;
                cin>>x>>y;
                for( int j=1; j<=x; j++ ){
                        for( int h=1; h<=y; h++ ){
                                cin>>a[j][h];
                        }
                }
                vector<int>s,d;
                int k;
                int cnt = 0;
                for( int j=1; j<=x; j++ ){
                        k = 0;
                        s.clear();
                        for( int h=1; h<=y; h++ ){
                                if( a[j][h] == '*' )k++;
                                s.push_back(j);
                                s.push_back(h);
                        }
                        cnt = max(cnt,k);
                }
                for( int j=1; j<=x; j++ ){
                        s.clear();
                        for( int h=1; h<=y; h++ ){
                                if( a[j][h] == '*' )k++;
                                s.push_back(j);
                                s.push_back(h);
                        }
                        if( k == cnt ){
                                for( int k = 0; k < s.size(); k++ ){
                                        used[s[k]][s[k+1]] = true;
                                        d.push_back(s[k]);
                                        d.push_back(s[k+1]);
                                }
                        }
                }
                int ans = 0;
                for( int j=1; j<=y; j++ ){
                        k = 0;
                        for( int h=1; h<=x; h++ ){
                                if( a[h][j] == '*' )k++;
                                else{
                                        if( used[h][j] )k++;
                                }
                        }
                        ans = max(ans,k);
                }
                for( int j=0; j<d.size(); j+=2 ){
                        used[d[j]][d[j+1]] = false;
                }
                cout<< ( y - cnt ) + ( x - ans ) << endl;
        }
}


#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 30010;
const long long mod = 998244353;

using namespace std;

int n,m;
vector< vector< bool > > used;
vector< vector< char > > a;

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        cin>>n;
        for( int i=1; i<=n; i++ ){
                int x,y;
                cin>>x>>y;
                a.clear();
                used.clear();
                a.resize(x + 2);
                used.resize(x + 2);
                for(int i = 0; i <= x + 1; i++){
                        for(int j = 0; j <= y + 1; j++){
                                a[i].push_back(0);
                                used[i].push_back(false);
                        }
                }
                for( int j=1; j<=x; j++ ){
                        for( int h=1; h<=y; h++ ){
                                cin>>a[j][h];
                        }
                }
                vector<int>s,d;
                int k;
                int cnt = 0;
                for( int j=1; j<=x; j++ ){
                        k = 0;
                        s.clear();
                        for( int h=1; h<=y; h++ ){
                                if( a[j][h] == '*' )k++;
                                s.push_back(j);
                                s.push_back(h);
                        }
                        cnt = max(cnt,k);
                }
                for( int j=1; j<=x; j++ ){
                        s.clear();
                        for( int h=1; h<=y; h++ ){
                                if( a[j][h] == '*' )k++;
                                s.push_back(j);
                                s.push_back(h);
                        }
                        if( k == cnt ){
                                for( int k = 0; k < s.size(); k++ ){
                                        used[s[k]][s[k+1]] = true;
                                        d.push_back(s[k]);
                                        d.push_back(s[k+1]);
                                }
                        }
                }
                int ans = 0;
                for( int j=1; j<=y; j++ ){
                        k = 0;
                        for( int h=1; h<=x; h++ ){
                                if( a[h][j] == '*' )k++;
                                else{
                                        if( used[h][j] )k++;
                                }
                        }
                        ans = max(ans,k);
                }
                for( int j=0; j<d.size(); j+=2 ){
                        used[d[j]][d[j+1]] = false;
                }
                cout<< ( y - cnt ) + ( x - ans ) << endl;
        }
}


#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 2010;
const long long mod = 998244353;

using namespace std;

int n,m;
char a[N][N];

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        cin>>n;
        for( int i=1; i<=n; i++ ){
                int x,y;
                cin>>x>>y;
                for( int j=1; j<=x; j++ ){
                        for( int h=1; h<=y; h++ ){
                                cin>>a[j][h];
                        }
                }
                vector<int>v;
                int k;
                for( int j=1; j<=x; j++ ){
                        k = 0;
                        for( int h=1; h<=y; h++ ){
                                if( a[j][h] == '*' )k++;
                        }
                        v.push_back(k);
                }
                sort(v.begin(),v.end());
                int z = v.back();
                vector<int>v1;
                for( int j=1; j<=y; j++ ){
                        k = 0;
                        for( int h=1; h<=x; h++ ){
                                if( a[h][j] == '*' )k++;
                        }
                        v1.push_back(k);
                }
                sort( v1.begin(), v1.end() );
                int g = v1.back();
                cout<< ( y - z ) + ( x - g ) << endl;
        }
}


#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 20100;
const long long mod = 998244353;

using namespace std;

int n,m;
char a[N][N];

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        cin>>n;
        for( int i=1; i<=n; i++ ){
                int x,y;
                cin>>x>>y;
                for( int j=1; j<=x; j++ ){
                        for( int h=1; h<=y; h++ ){
                                cin>>a[j][h];
                        }
                }
                vector<int>v;
                int k;
                for( int j=1; j<=x; j++ ){
                        k = 0;
                        for( int h=1; h<=y; h++ ){
                                if( a[j][h] == '*' )k++;
                        }
                        v.push_back(k);
                }
                sort(v.begin(),v.end());
                int z = v.back();
                vector<int>v1;
                for( int j=1; j<=y; j++ ){
                        k = 0;
                        for( int h=1; h<=x; h++ ){
                                if( a[h][j] == '*' )k++;
                        }
                        v1.push_back(k);
                }
                sort( v1.begin(), v1.end() );
                int g = v1.back();
                cout<< ( y - z ) + ( x - g ) << endl;
        }
}


constexpr auto Inf = 0X3F3F3F3F;
#ifndef LOCAL
	#include <bits/stdc++.h>
#endif
typedef long long LL;
using namespace std;

namespace IO {
	inline LL read() {
		LL o = 0, f = 1; char c = getchar();
		while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
		while (c > '/' && c < ':') { o = o * 10 + c - '0'; c = getchar(); }
		return o * f;
	}
	inline char recd() {
		char o; while ((o = getchar()) != '*' && o != '.'); return o;
	}
}
using namespace IO;

const int SIZE = 4E5 + 7, Mod = 1E9 + 7;

int m[SIZE << 1], p[SIZE], q[SIZE];

int main() {
	int T = read(), N, M;
	while (T--) {
		N = read(), M = read();
		for (int v = 1; v <= N; v++) {
			q[v] = 0;
			for (int u = 1, d; u <= M; u++) {
				d = (recd() == '.'), p[u] += d, q[v] += d;
				m[v * M + u] = d;
			}
		}
		int ans = Inf;
		for (int v = 1; v <= N; v++) {
			for (int u = 1; u <= M; u++) {
				ans = min(ans, p[u] + q[v] - m[v * M + u]);
			}
		} printf("%d\n", ans);
		memset(p, 0, sizeof p);
	}
}


constexpr auto Inf = 0X3F3F3F3F;
#ifndef LOCAL
	#include <bits/stdc++.h>
#endif
typedef long long LL;
using namespace std;

namespace IO {
	inline LL read() {
		LL o = 0, f = 1; char c = getchar();
		while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
		while (c > '/' && c < ':') { o = o * 10 + c - '0'; c = getchar(); }
		return o * f;
	}
	inline char recd() {
		char o; while ((o = getchar()) != '*' && o != '.'); return o;
	}
}
using namespace IO;

const int SIZE = 4E5 + 7, Mod = 1E9 + 7;

int m[SIZE], p[SIZE], e[SIZE];

int main() {
	int T = read(), N, M; pair<int, int> L, R;
	while (T--) {
		N = read(), M = read();
		L = R = make_pair(-1, 0);
		for (int v = 1; v <= N; v++) {
			e[v] = 0;
			for (int u = 1, d; u <= M; u++) {
				d = recd() == '*', p[u] += d, e[v] += d;
				m[v * N + u] = d;
			}
			if (L.first < e[v]) L = make_pair(e[v], v);
		}
		int ans = Inf;
		for (int v = 1; v <= N; v++) {
			for (int u = 1; u <= M; u++) {
				ans = min(ans, N + M - (e[v] + p[u] + (m[v * N + u] == 0 ? 1 : 0)));
			}
		} printf("%d\n", ans);
		memset(p, 0, sizeof p);
	}
}


constexpr auto Inf = 0X3F3F3F3F;
#ifndef LOCAL
	#include <bits/stdc++.h>
#endif
typedef long long LL;
using namespace std;

namespace IO {
	inline LL read() {
		LL o = 0, f = 1; char c = getchar();
		while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
		while (c > '/' && c < ':') { o = o * 10 + c - '0'; c = getchar(); }
		return o * f;
	}
	inline char recd() {
		char o; while ((o = getchar()) != '*' && o != '.'); return o;
	}
}
using namespace IO;

const int SIZE = 4E5 + 7, Mod = 1E9 + 7;

int m[SIZE << 1], p[SIZE], q[SIZE];

vector<int> C, R;

int main() {
	int T = read(), N, M;
	while (T--) {
		N = read(), M = read();
		for (int v = 1; v <= N; v++) {
			q[v] = 0;
			for (int u = 1, d; u <= M; u++) {
				d = (recd() == '.'), p[u] += d, q[v] += d;
				m[v * M + u] = d;
			}
		}
		int MR = Inf, MC = Inf;
		for (int v = 1; v <= N; v++) MC = min(MC, q[v]);
		for (int u = 1; u <= M; u++) MR = min(MR, p[u]);
		for (int v = 1; v <= N; v++) if (MC == q[v]) C.push_back(v);
		for (int u = 1; u <= M; u++) if (MR == p[u]) R.push_back(u);

		int ans = Inf;
		for (auto v : C) {
			for (auto u : R)
				ans = min(ans, p[u] + q[v] - m[v * M + u]);
			if (ans == MC + MR - 1) break;
		} printf("%d\n", ans);
		memset(p, 0, sizeof p); C.clear(), R.clear();
	}
}


constexpr auto Inf = 0X3F3F3F3F;
#ifndef LOCAL
	#include <bits/stdc++.h>
#endif
typedef long long LL;
using namespace std;

namespace IO {
	inline LL read() {
		LL o = 0, f = 1; char c = getchar();
		while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
		while (c > '/' && c < ':') { o = o * 10 + c - '0'; c = getchar(); }
		return o * f;
	}
	inline char recd() {
		char o; while ((o = getchar()) != '*' && o != '.'); return o;
	}
}
using namespace IO;

const int SIZE = 4E5 + 7, Mod = 1E9 + 7;

int m[SIZE << 1], p[SIZE], q[SIZE];

int main() {
	int T = read(), N, M;
	while (T--) {
		N = read(), M = read();
		for (int v = 1; v <= N; v++) {
			q[v] = 0;
			for (int u = 1, d; u <= M; u++) {
				d = (recd() == '.'), p[u] += d, q[v] += d;
				m[v * M + u] = d;
			}
		}
		int MR = Inf, MC = Inf;
		for (int v = 1; v <= N; v++) MC = min(MC, q[v]);
		for (int u = 1; u <= M; u++) MR = min(MR, p[u]);

		int ans = MC + MR;
		for (int v = 1; v <= N; v++) {
			for (int u = 1; u <= M; u++)
				if (q[v] == MC && p[u] == MR) {
					if (m[v * M + u]) { ans--; break; }
				}
			if (ans < MR + MC) break;
		} printf("%d\n", ans);
		for (int u = 1; u <= M; u++) p[u] = 0;
	}
}


constexpr auto Inf = 0X3F3F3F3F;
#ifndef LOCAL
	#include <bits/stdc++.h>
#endif
typedef long long LL;
using namespace std;

namespace IO {
	inline LL read() {
		LL o = 0, f = 1; char c = getchar();
		while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
		while (c > '/' && c < ':') { o = o * 10 + c - '0'; c = getchar(); }
		return o * f;
	}
	inline char recd() {
		char o; while ((o = getchar()) != '*' && o != '.'); return o;
	}
}
using namespace IO;

const int SIZE = 4E5 + 7, Mod = 1E9 + 7;

int m[SIZE << 1], p[SIZE], q[SIZE];

int main() {
	int T = read(), N, M;
	while (T--) {
		N = read(), M = read();
		for (int v = 1; v <= N; v++) {
			q[v] = 0;
			for (int u = 1, d; u <= M; u++) {
				d = recd() == '.', p[u] += d, q[v] += d;
				m[v * N + u] = d;
			}
		}
		int ans = Inf;
		for (int v = 1; v <= N; v++) {
			for (int u = 1; u <= M; u++) {
				ans = min(ans, p[u] + q[v] - m[v * N + u]);
			}
		} printf("%d\n", ans);
		memset(p, 0, sizeof p);
	}
}


constexpr auto Inf = 0X3F3F3F3F;
#ifndef LOCAL
	#include <bits/stdc++.h>
#endif
typedef long long LL;
using namespace std;

namespace IO {
	inline LL read() {
		LL o = 0, f = 1; char c = getchar();
		while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
		while (c > '/' && c < ':') { o = o * 10 + c - '0'; c = getchar(); }
		return o * f;
	}
	inline char recd() {
		char o; while ((o = getchar()) != '*' && o != '.'); return o;
	}
}
using namespace IO;

const int SIZE = 4E5 + 7, Mod = 1E9 + 7;

int m[SIZE << 1], p[SIZE], q[SIZE];

int C[SIZE], R[SIZE];

int main() {
	int T = read(), N, M;
	while (T--) {
		N = read(), M = read();
		for (int v = 1; v <= N; v++) {
			q[v] = 0;
			for (int u = 1, d; u <= M; u++) {
				d = (recd() == '.'), p[u] += d, q[v] += d;
				m[v * M + u] = d;
			}
		}
		int MR = Inf, MC = Inf;
		for (int v = 1; v <= N; v++) MC = min(MC, q[v]);
		for (int u = 1; u <= M; u++) MR = min(MR, p[u]);
		for (int v = 1; v <= N; v++) if (MC == q[v]) C[++C[0]] = v;
		for (int u = 1; u <= M; u++) if (MR == p[u]) R[++R[0]] = u;

		int ans = MC + MR;
		for (int v = 1; v <= C[0]; v++) {
			int f = 0;
			for (int u = 1; u <= R[0]; u++)
				if (m[C[v] * M + R[u]]) { f = 1; break; }
			if (f) { ans--; break; }
		} printf("%d\n", ans);
		memset(p, 0, sizeof p); C[0] = R[0] = 0;
	}
}


constexpr auto Inf = 0X3F3F3F3F;
#ifndef LOCAL
	#include <bits/stdc++.h>
#endif
typedef long long LL;
using namespace std;

namespace IO {
	inline LL read() {
		LL o = 0, f = 1; char c = getchar();
		while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
		while (c > '/' && c < ':') { o = o * 10 + c - '0'; c = getchar(); }
		return o * f;
	}
	inline char recd() {
		char o; while ((o = getchar()) != '*' && o != '.'); return o;
	}
}
using namespace IO;

const int SIZE = 4E5 + 7, Mod = 1E9 + 7;

vector<int> vec[SIZE]; int p[SIZE];

int main() {
	int T = read(), N, M; pair<int, int> L, R;
	while (T--) {
		N = read(), M = read();
		L = R = make_pair(-1, 0);
		for (int v = 1, c = 0; v <= N; v++, c = 0) {
			for (int u = 1, d; u <= M; u++) {
				d = recd() == '*', p[u] += d, c += d;
				vec[v].push_back(d);
			}
			if (L.first < c) L = make_pair(c, v);
		}
		for (int u = 1; u <= M; u++)
			if (R.first < p[u] || (R.first == p[u] && vec[L.second][R.second - 1] == 1)) R = make_pair(p[u], u);
		printf("%d\n", N + M - (L.first + R.first + (vec[L.second][R.second - 1] == 0 ? 1 : 0)));
		memset(p, 0, sizeof p);
		for (int pos = 1; pos <= N; pos++) vec[pos].clear();
	}
}


constexpr auto Inf = 0X3F3F3F3F;
#ifndef LOCAL
#include <bits/stdc++.h>
#endif
typedef long long LL;
using namespace std;

namespace IO {
	inline LL read() {
		LL o = 0, f = 1; char c = getchar();
		while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
		while (c > '/' && c < ':') { o = o * 10 + c - '0'; c = getchar(); }
		return o * f;
	}
	inline char recd() {
		char o; while ((o = getchar()) != '*' && o != '.'); return o;
	}
}
using namespace IO;

const int SIZE = 4E5 + 7, Mod = 1E9 + 7;

int m[SIZE << 1], p[SIZE], q[SIZE];

int C[SIZE], R[SIZE];

int main() {
	int T = read(), N, M;
	while (T--) {
		N = read(), M = read();
		for (int v = 1; v <= N; v++) {
			q[v] = 0;
			for (int u = 1, d; u <= M; u++) {
				d = (recd() == '.'), p[u] += d, q[v] += d;
				m[v * M + u] = d;
			}
		}
		int MR = Inf, MC = Inf;
		for (int v = 1; v <= N; v++) MC = min(MC, q[v]);
		for (int u = 1; u <= M; u++) MR = min(MR, p[u]);
		for (int v = 1; v <= N; v++) if (MC == q[v]) C[++C[0]] = v;
		for (int u = 1; u <= M; u++) if (MR == p[u]) R[++R[0]] = u;

		int ans = MC + MR;
		for (int v = 1; v <= C[0]; v++) {
			int f = 0;
			for (int u = 1; u <= R[0]; u++)
				if (m[C[v] * M + R[u]]) { f = 1; break; }
			if (f) { ans--; break; }
		} printf("%d\n", ans);
		for (int u = 1; u <= M; u++) p[u] = 0; C[0] = R[0] = 0;
	}
}


constexpr auto Inf = 0X3F3F3F3F;
#ifndef LOCAL
	#include <bits/stdc++.h>
#endif
typedef long long LL;
using namespace std;

namespace IO {
	inline LL read() {
		LL o = 0, f = 1; char c = getchar();
		while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
		while (c > '/' && c < ':') { o = o * 10 + c - '0'; c = getchar(); }
		return o * f;
	}
	inline char recd() {
		char o; while ((o = getchar()) != '*' && o != '.'); return o;
	}
}
using namespace IO;

const int SIZE = 4E5 + 7, Mod = 1E9 + 7;

int m[SIZE << 1], p[SIZE], q[SIZE];

int main() {
	int T = read(), N, M;
	while (T--) {
		N = read(), M = read();
		for (int v = 1; v <= N; v++) {
			q[v] = 0;
			for (int u = 1, d; u <= M; u++) {
				d = (recd() == '.'), p[u] += d, q[v] += d;
				m[v * N + u] = d;
			}
		}
		int ans = Inf;
		for (int v = 1; v <= N; v++) {
			for (int u = 1; u <= M; u++) {
				ans = min(ans, p[u] + q[v] - m[v * N + u]);
			}
		} printf("%d\n", ans);
		memset(p, 0, sizeof p);
	}
}


constexpr auto Inf = 0X3F3F3F3F;
#ifndef LOCAL
	#include <bits/stdc++.h>
#endif
typedef long long LL;
using namespace std;

namespace IO {
	inline LL read() {
		LL o = 0, f = 1; char c = getchar();
		while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
		while (c > '/' && c < ':') { o = o * 10 + c - '0'; c = getchar(); }
		return o * f;
	}
	inline char recd() {
		char o; while ((o = getchar()) != '*' && o != '.'); return o;
	}
}
using namespace IO;

const int SIZE = 4E5 + 7, Mod = 1E9 + 7;

vector<int> vec[SIZE]; int p[SIZE], e[SIZE];

int main() {
	int T = read(), N, M; pair<int, int> L, R;
	while (T--) {
		N = read(), M = read();
		L = R = make_pair(-1, 0);
		for (int v = 1; v <= N; v++) {
			e[v] = 0;
			for (int u = 1, d; u <= M; u++) {
				d = recd() == '*', p[u] += d, e[v] += d;
				vec[v].push_back(d);
			}
			if (L.first < e[v]) L = make_pair(e[v], v);
		}
		int ans = Inf;
		for (int v = 1; v <= N; v++) {
			for (int u = 1, d; u <= M; u++) {
				ans = min(ans, N + M - (e[v] + p[u] + (vec[v][u - 1] == 0 ? 1 : 0)));
			}
		}
		printf("%d\n", ans);
		memset(p, 0, sizeof p);
		for (int pos = 1; pos <= N; pos++) vec[pos].clear();
	}
}


#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#define oo 2000000000
#define N 400100
#define pb push_back
#define mk make_pair
#define LL int
#define imid LL mid=(l+r)>>1
#define LD long double
#define mod 998244353
#define nsd __gcd
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int ii=1;ii<=t;ii++){
        int n,m;
        int ans=oo;
        unordered_map <int,int> a[n+10];
        int x[N]={0},y[N]={0};
        cin>>n>>m;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                char c;
                cin>>c;
                if(c=='*'){
                    a[i][j]=1;
                    x[i]++;
                    y[j]++;
                }
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                ans=min(ans,n-x[i]+m-y[j]+a[i][j]-1);
                //cout<<ans<<" "<<n-x[i]<<" "<<m-y[j]<<endl;
            }
        }
        cout<<ans<<endl;
    }
}


#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#define oo 2000000000
#define N 400100
#define pb push_back
#define mk make_pair
#define LL int
#define imid LL mid=(l+r)>>1
#define LD long double
#define mod 998244353
#define nsd __gcd
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    for(int ii=1;ii<=t;ii++){
        int n,m;
        int ans=oo;
        cin>>n>>m;
        map <pair<int,int>, int> a;
        int x[N]={0},y[N]={0};

        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                char c;
                cin>>c;
                if(c=='*'){
                    a[mk(i,j)]=1;
                    x[i]++;
                    y[j]++;
                }
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                ans=min(ans,n-x[i]+m-y[j]+a[mk(i,j)]-1);
                //cout<<ans<<" "<<n-x[i]<<" "<<m-y[j]<<endl;
            }
        }
        cout<<ans<<endl;
    }
}


#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#define oo 2000000000
#define N 40100
#define pb push_back
#define mk make_pair
#define LL int
#define imid LL mid=(l+r)>>1
#define LD long double
#define mod 998244353
#define nsd __gcd
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int ii=1;ii<=t;ii++){
        int n,m;
        int ans=oo;
        cin>>n>>m;
        map <pair<int,int>, int> a;
        int x[N]={0},y[N]={0};

        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                char c;
                cin>>c;
                if(c=='*'){
                    a[mk(i,j)]=1;
                    x[i]++;
                    y[j]++;
                }
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                ans=min(ans,n-x[i]+m-y[j]+a[mk(i,j)]-1);
                //cout<<ans<<" "<<n-x[i]<<" "<<m-y[j]<<endl;
            }
        }
        cout<<ans<<endl;
    }
}


#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#define oo 2000000000
#define N 400100
#define pb push_back
#define mk make_pair
#define LL int
#define imid LL mid=(l+r)>>1
#define LD long double
#define mod 998244353
#define nsd __gcd
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    for(int ii=1;ii<=t;ii++){
        int n,m;
        int ans=oo;
        cin>>n>>m;
        int a[n+5][m+5]={0};
        int x[n+5]={0},y[m+5]={0};

        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                char c;
                cin>>c;
                if(c=='*'){
                    a[i][j]=1;
                    x[i]++;
                    y[j]++;
                }
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                ans=min(ans,n-x[i]+m-y[j]+a[i][j]-1);
                //cout<<ans<<" "<<n-x[i]<<" "<<m-y[j]<<endl;
            }
        }
        cout<<ans<<'\n';
    }
}


#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#define oo 2000000000
#define N 400100
#define pb push_back
#define mk make_pair
#define LL int
#define imid LL mid=(l+r)>>1
#define LD long double
#define mod 998244353
#define nsd __gcd
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int ii=1;ii<=t;ii++){
        int n,m;
        int ans=oo;
        unordered_map <int,int> a[m+10];
        int x[N]={0},y[N]={0};
        cin>>n>>m;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                char c;
                cin>>c;
                if(c=='*'){
                    a[i][j]=1;
                    x[i]++;
                    y[j]++;
                }
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                ans=min(ans,n-x[i]+m-y[j]+a[i][j]-1);
                //cout<<ans<<" "<<n-x[i]<<" "<<m-y[j]<<endl;
            }
        }
        cout<<ans<<endl;
    }
}


#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#define oo 2000000000
#define N 400100
#define pb push_back
#define mk make_pair
#define LL int
#define imid LL mid=(l+r)>>1
#define LD long double
#define mod 998244353
#define nsd __gcd
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    for(int ii=1;ii<=t;ii++){
        int n,m;
        int ans=oo;
        cin>>n>>m;
        unordered_map <pair<int,int>, int> a;
        int x[N]={0},y[N]={0};

        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                char c;
                cin>>c;
                if(c=='*'){
                    a[mk(i,j)]=1;
                    x[i]++;
                    y[j]++;
                }
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                ans=min(ans,n-x[i]+m-y[j]+a[mk(i,j)]-1);
                //cout<<ans<<" "<<n-x[i]<<" "<<m-y[j]<<endl;
            }
        }
        cout<<ans<<'\n';
    }
}


#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#define oo 2000000000
#define N 400100
#define pb push_back
#define mk make_pair
#define LL int
#define imid LL mid=(l+r)>>1
#define LD long double
#define mod 998244353
#define nsd __gcd
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    for(int ii=1;ii<=t;ii++){
        int n,m;
        int ans=oo;
        cin>>n>>m;
        map <pair<int,int>, int> a;
        int x[N]={0},y[N]={0};

        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                char c;
                cin>>c;
                if(c=='*'){
                    a[mk(i,j)]=1;
                    x[i]++;
                    y[j]++;
                }
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                ans=min(ans,n-x[i]+m-y[j]+a[mk(i,j)]-1);
                //cout<<ans<<" "<<n-x[i]<<" "<<m-y[j]<<endl;
            }
        }
        cout<<ans<<'\n';
    }
}


#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#define oo 2000000000
#define N 400100
#define pb push_back
#define mk make_pair
#define LL int
#define imid LL mid=(l+r)>>1
#define LD long double
#define mod 998244353
#define nsd __gcd
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int ii=1;ii<=t;ii++){
        int n,m;
        int ans=oo;
        cin>>n>>m;
        map <pair<int,int>, int> a;
        int x[N]={0},y[N]={0};

        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                char c;
                cin>>c;
                if(c=='*'){
                    a[mk(i,j)]=1;
                    x[i]++;
                    y[j]++;
                }
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                ans=min(ans,n-x[i]+m-y[j]+a[mk(i,j)]-1);
                //cout<<ans<<" "<<n-x[i]<<" "<<m-y[j]<<endl;
            }
        }
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    long long t;
    cin>>t;
    while(t-->0){
        long long n,m;
        cin>>n>>m;
        string s[500004];
        for(long long i=0;i<n;i++){
            cin>>s[i];
        }
        long long countr[500005],countc[500005];
        for(long long i=0;i<n;i++){
            long long co=0;
            for(long long j=0;j<m;j++){
                if(s[i][j]=='.'){
                    co++;
                }
            }
            countr[i]=co;
        }
        for(long long i=0;i<m;i++){
            long long co=0;
            for(long long j=0;j<n;j++){
                if(s[j][i]=='.'){
                    co++;
                }
            }
            countc[i]=co;
        }
        long long mini=1000005;
        for(long long i=0;i<n;i++){
            for(long long j=0;j<m;j++){
                if(s[i][j]=='.'){
                    mini = min(countr[i]+countc[j]-1,mini);
                }else{
                    mini = min(countr[i]+countc[j],mini);
                }
            }
        }
        cout<<mini<<"\n";

    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    long long t;
    cin>>t;
    while(t-->0){
        long long n,m;
        cin>>n>>m;
        string s[500004];
        for(long long i=0;i<n;i++){
            cin>>s[i];
        }
        long long countr[500005]={0},countc[500005]={0};
        for(long long i=0;i<n;i++){
            for(long long j=0;j<m;j++){
                if(s[i][j]=='.'){
                    countr[i]++;
                    countc[j]++;
                }
            }
        }

        long long mini=1000005;
        for(long long i=0;i<n;i++){
            for(long long j=0;j<m;j++){
                if(s[i][j]=='.'){
                    mini = min(countr[i]+countc[j]-1,mini);
                }else{
                    mini = min(countr[i]+countc[j],mini);
                }
            }
        }
        cout<<mini<<"\n";

    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    long long t;
    cin>>t;
    while(t-->0){
        int n,m;
        cin>>n>>m;
        vector<string> s(n)
        for(long long i=0;i<n;i++){
            cin>>s[i];
        }
        vector<int>countr(n,0),countc(m,0);
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(s[i][j]=='.'){
                    countr[i]++;
                    countc[j]++;
                }
            }
        }

        int mini=100005;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(s[i][j]=='.'){
                    mini = min(countr[i]+countc[j]-1,mini);
                }else{
                    mini = min(countr[i]+countc[j],mini);
                }
            }
        }
        cout<<mini<<"\n";

    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{

    int t;
    scanf("%d",&t);
    while(t-->0){
        int n,m;
        cin>>n>>m;
        scanf("%d",&n);
        scanf("%d",&m);
        string s[50004];
        for(long long i=0;i<n;i++){
            cin>>s[i];
        }
        int countr[50005]={0},countc[50005]={0};
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(s[i][j]=='.'){
                    countr[i]++;
                    countc[j]++;
                }
            }
        }

        int mini=100005;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(s[i][j]=='.'){
                    mini = min(countr[i]+countc[j]-1,mini);
                }else{
                    mini = min(countr[i]+countc[j],mini);
                }
            }
        }
        printf("%d\n",mini);

    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    long long t;
    cin>>t;
    while(t-->0){
        int n,m;
        cin>>n>>m;
        string s[50004];
        for(long long i=0;i<n;i++){
            cin>>s[i];
        }
        int countr[50005]={0},countc[50005]={0};
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(s[i][j]=='.'){
                    countr[i]++;
                    countc[j]++;
                }
            }
        }

        int mini=100005;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(s[i][j]=='.'){
                    mini = min(countr[i]+countc[j]-1,mini);
                }else{
                    mini = min(countr[i]+countc[j],mini);
                }
            }
        }
        cout<<mini<<"\n";

    }
    return 0;
}


//Author:Medo king
//Created For : Div 2 Round #484
//ان الله لا يضيع اجر من احسن عملا
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <hash_map>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <math.h>
#include <cassert>
#include <cstring>
#define ll long long
#define ld long double
#define PI acos(-1)
#define oo 1e9
#define rep (i == x ? '\n' : ' ')
#define MEDO_journey_TO_ICPC cin.tie(0);std :: ios :: sync_with_stdio (false);

//ll di[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
//ll dj[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

//ll gcd(ll first, ll second) { return !second ? first : gcd(second, first % second); }
//ll lcm(ll first, ll second) { return (first / gcd(first, second)) * second; }

using namespace std;

ll x, y;
bool b = 1;
deque<ll>q, v;
map<ll, ll>p;

int main(){

	MEDO_journey_TO_ICPC;

	cin >> x;

	for (int i = 0; i < x; i++){
		cin >> y;
		q.push_back(y);
		if (y == 0 && b){
			p[0] = i;
			b = 0;
		}
	}
	for (int i = 0; i < x; i++){
		if (q[i] == 0){
			v.push_back(0);
			p[0] = i;
		}
		else{
			ll mini = abs(i - p[0]), c = 50000;
			if (q[q.size() - 1] == 0){
				v.push_back(min(mini, abs(i - (ll)(q.size() - 1))));
				continue;
			}
			if (i != x - 1){
				for (int j = 1, s = i + 1; c >= 0 && s < x && j <= abs(i - p[0]); c--, j++, s++){
					if (q[s] == 0){
						mini = abs(s - i);
						break;
					}
				}
			}
			v.push_back(mini);
		}
	}
	while (!v.empty()){
		cout << v.front() << " ";
		v.pop_front();
	}
	cout << endl;
	return 0;
}


//Author:Medo king
//Created For : Div 2 Round #484
//ان الله لا يضيع اجر من احسن عملا
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <hash_map>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <math.h>
#include <cassert>
#include <cstring>
#define ll long long
#define ld long double
#define PI acos(-1)
#define oo 1e9
#define rep (i == x ? '\n' : ' ')
#define MEDO_journey_TO_ICPC cin.tie(0);std :: ios :: sync_with_stdio (false);

//ll di[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
//ll dj[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

//ll gcd(ll first, ll second) { return !second ? first : gcd(second, first % second); }
//ll lcm(ll first, ll second) { return (first / gcd(first, second)) * second; }

using namespace std;

ll x, arr[200005], ans[200005];
stack<ll>s;

int main(){

	MEDO_journey_TO_ICPC;

	cin >> x;
	fill(ans, ans + x, 10000000);
	for (int i = 0; i < x; i++)
		cin >> arr[i];
	for (int i = 0; i < x; i++){
		s.push(i);
		if (arr[i]) continue;
		while (s.size()){
			ans[s.top()] = i - s.top();
			s.pop();
		}
	}
	while (s.size()) s.pop();
	for (int i = x - 1; ~i; i--){
		s.push(i);
		if (arr[i]) continue;
		while (s.size()){
			ans[s.top()] = min(ans[s.top()], s.top() - i);
			s.pop();
		}
	}
	for (int i = 0; i < x; i++)
		cout << ans[i] << " ";
	cout << endl;
	return 0;
}


//Author:Medo king
//Created For : Div 2 Round #484
//ان الله لا يضيع اجر من احسن عملا
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <hash_map>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <math.h>
#include <cassert>
#include <cstring>
#define ll long long
#define ld long double
#define PI acos(-1)
#define oo 1e9
#define rep (i == x ? '\n' : ' ')
#define MEDO_journey_TO_ICPC cin.tie(0);std :: ios :: sync_with_stdio (false);

//ll di[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
//ll dj[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

//ll gcd(ll first, ll second) { return !second ? first : gcd(second, first % second); }
//ll lcm(ll first, ll second) { return (first / gcd(first, second)) * second; }

using namespace std;

ll x, y;
bool b = 1;
deque<ll>q, v;
map<ll, ll>p;

int main(){

	MEDO_journey_TO_ICPC;

	cin >> x;

	for (int i = 0; i < x; i++){
		cin >> y;
		q.push_back(y);
		if (y == 0 && b){
			p[0] = i;
			b = 0;
		}
	}
	for (int i = 0; i < x; i++){
		if (q[i] == 0){
			v.push_back(0);
			p[0] = i;
		}
		else{
			v.push_back(abs(i - p[0]));
		}
	}
	while (!v.empty()){
		cout << v.front() << " ";
		v.pop_front();
	}
	cout << endl;
	return 0;
}


//Author:Medo king
//Created For : Div 2 Round #484
//ان الله لا يضيع اجر من احسن عملا
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <hash_map>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <math.h>
#include <cassert>
#include <cstring>
#define ll long long
#define ld long double
#define PI acos(-1)
#define oo 1e9
#define rep (i == x ? '\n' : ' ')
#define MEDO_journey_TO_ICPC cin.tie(0);std :: ios :: sync_with_stdio (false);

//ll di[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
//ll dj[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

//ll gcd(ll first, ll second) { return !second ? first : gcd(second, first % second); }
//ll lcm(ll first, ll second) { return (first / gcd(first, second)) * second; }

using namespace std;

ll x, y;
bool b = 1;
deque<ll>q, v;
map<ll, ll>p;

int main(){

	MEDO_journey_TO_ICPC;

	cin >> x;

	for (int i = 0; i < x; i++){
		cin >> y;
		q.push_back(y);
		if (y == 0 && b){
			p[0] = i;
			b = 0;
		}
	}
	for (int i = 0; i < x; i++){
		if (q[i] == 0){
			v.push_back(0);
			p[0] = i;
		}
		else{
			ll c = 100000;
			ll mini = abs(i - p[0]);
			if (i != x - 1){
				for (int j = 1, s = i + 1; c >= 0 && s < x && j <= abs(i - p[0]); c--, j++, s++){
					if (q[s] == 0){
						mini = abs(s - i);
						break;
					}
				}
			}
			v.push_back(mini);
		}
	}
	while (!v.empty()){
		cout << v.front() << " ";
		v.pop_front();
	}
	cout << endl;
	return 0;
}


//Author:Medo king
//Created For : Div 2 Round #484
//ان الله لا يضيع اجر من احسن عملا
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <hash_map>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <math.h>
#include <cassert>
#include <cstring>
#define ll long long
#define ld long double
#define PI acos(-1)
#define oo 1e9
#define rep (i == x ? '\n' : ' ')
#define MEDO_journey_TO_ICPC cin.tie(0);std :: ios :: sync_with_stdio (false);

//ll di[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
//ll dj[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

//ll gcd(ll first, ll second) { return !second ? first : gcd(second, first % second); }
//ll lcm(ll first, ll second) { return (first / gcd(first, second)) * second; }

using namespace std;

ll x, y;
bool b = 1;
deque<ll>q, v;
map<ll, ll>p;

int main(){

	MEDO_journey_TO_ICPC;

	cin >> x;

	for (int i = 0; i < x; i++){
		cin >> y;
		q.push_back(y);
		if (y == 0 && b){
			p[0] = i;
			b = 0;
		}
	}
	for (int i = 0; i < x; i++){
		if (q[i] == 0){
			v.push_back(0);
			p[0] = i;
		}
		else{
			ll mini = abs(i - p[0]), c = 5000;
			if (q[q.size() - 1] == 0){
				v.push_back(min(mini, abs(i - (ll)(q.size() - 1))));
				continue;
			}
			if (i != x - 1){
				for (int j = 1, s = i + 1; c >= 0 && s < x && j <= abs(i - p[0]); c--, j++, s++){
					if (q[s] == 0){
						mini = abs(s - i);
						break;
					}
				}
			}
			v.push_back(mini);
		}
	}
	while (!v.empty()){
		cout << v.front() << " ";
		v.pop_front();
	}
	cout << endl;
	return 0;
}


//Author:Medo king
//Created For : Div 2 Round #484
//ان الله لا يضيع اجر من احسن عملا
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <hash_map>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <math.h>
#include <cassert>
#include <cstring>
#define ll long long
#define ld long double
#define PI acos(-1)
#define oo 1e9
#define rep (i == x ? '\n' : ' ')
#define MEDO_journey_TO_ICPC cin.tie(0);std :: ios :: sync_with_stdio (false);

//ll di[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
//ll dj[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

//ll gcd(ll first, ll second) { return !second ? first : gcd(second, first % second); }
//ll lcm(ll first, ll second) { return (first / gcd(first, second)) * second; }

using namespace std;

ll x, y, z = 0;
deque<ll>q, v;
map<ll, vector<ll>>p;

int main(){

	MEDO_journey_TO_ICPC;

	cin >> x;

	for (int i = 0; i < x; i++){
		cin >> y;
		q.push_back(y);
		if (y == 0){
			p[0].push_back(i);
			z++;
		}
	}
	if (z == q.size()){
		while (z > 0){
			cout << 0 << " ";
			z--;
		}
		return cout << endl, 0;
	}
	for (int i = 0; i < x; i++){
		if (q[i] == 0){
			v.push_back(0);
		}
		else{
			ll mini = oo;
			for (int j = 0; j < p[0].size(); j++){
				mini = min(mini, abs(p[0][j] - i));
			}
			v.push_back(mini);
		}
	}
	while (!v.empty()){
		cout << v.front() << " ";
		v.pop_front();
	}
	cout << endl;
	return 0;
}


//Author:Medo king
//Created For : Div 2 Round #484
//ان الله لا يضيع اجر من احسن عملا
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <hash_map>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <math.h>
#include <cassert>
#include <cstring>
#define ll long long
#define ld long double
#define PI acos(-1)
#define oo 1e9
#define rep (i == x ? '\n' : ' ')
#define MEDO_journey_TO_ICPC cin.tie(0);std :: ios :: sync_with_stdio (false);

//ll di[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
//ll dj[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

//ll gcd(ll first, ll second) { return !second ? first : gcd(second, first % second); }
//ll lcm(ll first, ll second) { return (first / gcd(first, second)) * second; }

using namespace std;

ll x, y;
bool b = 1;
deque<ll>q, v;
map<ll, ll>p;

int main(){

	MEDO_journey_TO_ICPC;

	cin >> x;

	for (int i = 0; i < x; i++){
		cin >> y;
		q.push_back(y);
		if (y == 0 && b){
			p[0] = i;
			b = 0;
		}
	}
	for (int i = 0; i < x; i++){
		if (q[i] == 0){
			v.push_back(0);
			p[0] = i;
		}
		else{
			if (i + 1 < x && q[i + 1] == 0){
				v.push_back(1);
				continue;
			}
			if (i + 2 < x && q[i + 2] == 0){
				v.push_back(min((ll)2, abs(i - p[0])));
				continue;
			}
			v.push_back(abs(i - p[0]));
		}
	}
	while (!v.empty()){
		cout << v.front() << " ";
		v.pop_front();
	}
	cout << endl;
	return 0;
}


//Author:Medo king
//Created For : Div 2 Round #484
//ان الله لا يضيع اجر من احسن عملا
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <hash_map>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <math.h>
#include <cassert>
#include <cstring>
#define ll long long
#define ld long double
#define PI acos(-1)
#define oo 1e9
#define rep (i == x ? '\n' : ' ')
#define MEDO_journey_TO_ICPC cin.tie(0);std :: ios :: sync_with_stdio (false);

//ll di[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
//ll dj[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

//ll gcd(ll first, ll second) { return !second ? first : gcd(second, first % second); }
//ll lcm(ll first, ll second) { return (first / gcd(first, second)) * second; }

using namespace std;

ll x, y;
bool b = 1;
deque<ll>q, v;
map<ll, ll>p;

int main(){

	MEDO_journey_TO_ICPC;

	cin >> x;

	for (int i = 0; i < x; i++){
		cin >> y;
		q.push_back(y);
		if (y == 0 && b){
			p[0] = i;
			b = 0;
		}
	}
	for (int i = 0; i < x; i++){
		if (q[i] == 0){
			v.push_back(0);
			p[0] = i;
		}
		else{
			ll mini = abs(i - p[0]), c = 500;
			if (q[q.size() - 1] == 0){
				v.push_back(min(mini, abs(i - (ll)(q.size() - 1))));
				continue;
			}
			if (i != x - 1){
				for (int j = 1, s = i + 1; c >= 0 && s < x && j <= abs(i - p[0]); c--, j++, s++){
					if (q[s] == 0){
						mini = abs(s - i);
						break;
					}
				}
			}
			v.push_back(mini);
		}
	}
	while (!v.empty()){
		cout << v.front() << " ";
		v.pop_front();
	}
	cout << endl;
	return 0;
}


//Author:Medo king
//Created For : Div 2 Round #484
//ان الله لا يضيع اجر من احسن عملا
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <hash_map>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <math.h>
#include <cassert>
#include <cstring>
#define ll long long
#define ld long double
#define PI acos(-1)
#define oo 1e9
#define rep (i == x ? '\n' : ' ')
#define MEDO_journey_TO_ICPC cin.tie(0);std :: ios :: sync_with_stdio (false);

//ll di[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
//ll dj[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

//ll gcd(ll first, ll second) { return !second ? first : gcd(second, first % second); }
//ll lcm(ll first, ll second) { return (first / gcd(first, second)) * second; }

using namespace std;

ll x, y;
bool b = 1;
deque<ll>q, v;
map<ll, ll>p;

int main(){

	MEDO_journey_TO_ICPC;

	cin >> x;

	for (int i = 0; i < x; i++){
		cin >> y;
		q.push_back(y);
		if (y == 0 && b){
			p[0] = i;
			b = 0;
		}
	}
	for (int i = 0; i < x; i++){
		if (q[i] == 0){
			v.push_back(0);
			p[0] = i;
		}
		else{
			ll mini = abs(i - p[0]), c = 15;
			if (q[q.size() - 1] == 0){
				v.push_back(min(mini, abs(i - (ll)(q.size() - 1))));
				continue;
			}
			if (i != x - 1){
				for (int j = 1, s = i + 1; c >= 0 && s < x && j <= abs(i - p[0]); c--, j++, s++){
					if (q[s] == 0){
						mini = abs(s - i);
						break;
					}
				}
			}
			v.push_back(mini);
		}
	}
	while (!v.empty()){
		cout << v.front() << " ";
		v.pop_front();
	}
	cout << endl;
	return 0;
}


//Author:Medo king
//Created For : Div 2 Round #484
//ان الله لا يضيع اجر من احسن عملا
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <hash_map>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <math.h>
#include <cassert>
#include <cstring>
#define ll long long
#define ld long double
#define PI acos(-1)
#define oo 1e9
#define rep (i == x ? '\n' : ' ')
#define MEDO_journey_TO_ICPC cin.tie(0);std :: ios :: sync_with_stdio (false);

//ll di[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
//ll dj[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

//ll gcd(ll first, ll second) { return !second ? first : gcd(second, first % second); }
//ll lcm(ll first, ll second) { return (first / gcd(first, second)) * second; }

using namespace std;

ll x, y;
bool b = 1;
deque<ll>q, v;
map<ll, ll>p;

int main(){

	MEDO_journey_TO_ICPC;

	cin >> x;

	for (int i = 0; i < x; i++){
		cin >> y;
		q.push_back(y);
		if (y == 0 && b){
			p[0] = i;
			b = 0;
		}
	}
	for (int i = 0; i < x; i++){
		if (q[i] == 0){
			v.push_back(0);
			p[0] = i;
		}
		else{
			ll mini = abs(i - p[0]), c = 15;
			if (q[q.size() - 1] == 0){
				v.push_back(min(mini, abs(i - q.size() - 1)));
			}
			if (i != x - 1){
				for (int j = 1, s = i + 1; c >= 0 && s < x && j <= abs(i - p[0]); c--, j++, s++){
					if (q[s] == 0){
						mini = abs(s - i);
						break;
					}
				}
			}
			v.push_back(mini);
		}
	}
	while (!v.empty()){
		cout << v.front() << " ";
		v.pop_front();
	}
	cout << endl;
	return 0;
}


//Author:Medo king
//Created For : Div 2 Round #484
//ان الله لا يضيع اجر من احسن عملا
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <hash_map>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <math.h>
#include <cassert>
#include <cstring>
#define ll long long
#define ld long double
#define PI acos(-1)
#define oo 1e9
#define rep (i == x ? '\n' : ' ')
#define MEDO_journey_TO_ICPC cin.tie(0);std :: ios :: sync_with_stdio (false);

//ll di[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
//ll dj[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

//ll gcd(ll first, ll second) { return !second ? first : gcd(second, first % second); }
//ll lcm(ll first, ll second) { return (first / gcd(first, second)) * second; }

using namespace std;

ll x, y;
bool b = 1;
deque<ll>q, v;
map<ll, ll>p;

int main(){

	MEDO_journey_TO_ICPC;

	cin >> x;

	for (int i = 0; i < x; i++){
		cin >> y;
		q.push_back(y);
		if (y == 0 && b){
			p[0] = i;
			b = 0;
		}
	}
	for (int i = 0; i < x; i++){
		if (q[i] == 0){
			v.push_back(0);
			p[0] = i;
		}
		else{
			ll mini = abs(i - p[0]), c = 15;
			if (q[q.size() - 1] == 0){
				v.push_back(min(mini, abs(i - q[q.size() - 1])));
			}
			if (i != x - 1){
				for (int j = 1, s = i + 1; c >= 0 && s < x && j <= abs(i - p[0]); c--, j++, s++){
					if (q[s] == 0){
						mini = abs(s - i);
						break;
					}
				}
			}
			v.push_back(mini);
		}
	}
	while (!v.empty()){
		cout << v.front() << " ";
		v.pop_front();
	}
	cout << endl;
	return 0;
}


//Author:Medo king
//Created For : Div 2 Round #484
//ان الله لا يضيع اجر من احسن عملا
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <hash_map>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <math.h>
#include <cassert>
#include <cstring>
#define ll long long
#define ld long double
#define PI acos(-1)
#define oo 1e9
#define rep (i == x ? '\n' : ' ')
#define MEDO_journey_TO_ICPC cin.tie(0);std :: ios :: sync_with_stdio (false);

//ll di[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
//ll dj[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

//ll gcd(ll first, ll second) { return !second ? first : gcd(second, first % second); }
//ll lcm(ll first, ll second) { return (first / gcd(first, second)) * second; }

using namespace std;

ll x, y;
bool b = 1;
deque<ll>q, v;
map<ll, ll>p;

int main(){

	MEDO_journey_TO_ICPC;

	cin >> x;

	for (int i = 0; i < x; i++){
		cin >> y;
		q.push_back(y);
		if (y == 0 && b){
			p[0] = i;
			b = 0;
		}
	}
	for (int i = 0; i < x; i++){
		if (q[i] == 0){
			v.push_back(0);
			p[0] = i;
		}
		else{
			ll mini = abs(i - p[0]), c = 15;
			if (q[q.size() - 1] == 0){
				v.push_back(min(mini, abs(i - (ll)(q.size() - 1))));
			}
			if (i != x - 1){
				for (int j = 1, s = i + 1; c >= 0 && s < x && j <= abs(i - p[0]); c--, j++, s++){
					if (q[s] == 0){
						mini = abs(s - i);
						break;
					}
				}
			}
			v.push_back(mini);
		}
	}
	while (!v.empty()){
		cout << v.front() << " ";
		v.pop_front();
	}
	cout << endl;
	return 0;
}


//Author:Medo king
//Created For : Div 2 Round #484
//ان الله لا يضيع اجر من احسن عملا
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <hash_map>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <math.h>
#include <cassert>
#include <cstring>
#define ll long long
#define ld long double
#define PI acos(-1)
#define oo 1e9
#define rep (i == x ? '\n' : ' ')
#define MEDO_journey_TO_ICPC cin.tie(0);std :: ios :: sync_with_stdio (false);

//ll di[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
//ll dj[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

//ll gcd(ll first, ll second) { return !second ? first : gcd(second, first % second); }
//ll lcm(ll first, ll second) { return (first / gcd(first, second)) * second; }

using namespace std;

ll x, y;
bool b = 1;
deque<ll>q, v;
map<ll, ll>p;

int main(){

	MEDO_journey_TO_ICPC;

	cin >> x;

	for (int i = 0; i < x; i++){
		cin >> y;
		q.push_back(y);
		if (y == 0 && b){
			p[0] = i;
			b = 0;
		}
	}
	for (int i = 0; i < x; i++){
		if (q[i] == 0){
			v.push_back(0);
			p[0] = i;
		}
		else{
			ll mini = abs(i - p[0]);
			if (i != x - 1){
				for (int j = 1, s = i + 1; s < x && j <= abs(i - p[0]); j++, s++){
					if (q[s] == 0){
						mini = abs(s - i);
						break;
					}
				}
			}
			v.push_back(mini);
		}
	}
	while (!v.empty()){
		cout << v.front() << " ";
		v.pop_front();
	}
	cout << endl;
	return 0;
}


//Author:Medo king
//Created For : Div 2 Round #484
//ان الله لا يضيع اجر من احسن عملا
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <hash_map>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <math.h>
#include <cassert>
#include <cstring>
#define ll long long
#define ld long double
#define PI acos(-1)
#define oo 1e9
#define rep (i == x ? '\n' : ' ')
#define MEDO_journey_TO_ICPC cin.tie(0);std :: ios :: sync_with_stdio (false);

//ll di[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
//ll dj[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

//ll gcd(ll first, ll second) { return !second ? first : gcd(second, first % second); }
//ll lcm(ll first, ll second) { return (first / gcd(first, second)) * second; }

using namespace std;

ll x, y;
bool b = 1;
deque<ll>q, v;
map<ll, ll>p;

int main(){

	MEDO_journey_TO_ICPC;

	cin >> x;

	for (int i = 0; i < x; i++){
		cin >> y;
		q.push_back(y);
		if (y == 0 && b){
			p[0] = i;
			b = 0;
		}
	}
	for (int i = 0; i < x; i++){
		if (q[i] == 0){
			v.push_back(0);
			p[0] = i;
		}
		else{
			ll c = 15;
			ll mini = abs(i - p[0]);
			if (i != x - 1){
				for (int j = 1, s = i + 1; c >= 0 && s < x && j <= abs(i - p[0]); c--, j++, s++){
					if (q[s] == 0){
						mini = abs(s - i);
						break;
					}
				}
			}
			v.push_back(mini);
		}
	}
	while (!v.empty()){
		cout << v.front() << " ";
		v.pop_front();
	}
	cout << endl;
	return 0;
}


//Author:Medo king
//Created For : Div 2 Round #484
//ان الله لا يضيع اجر من احسن عملا
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <hash_map>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <math.h>
#include <cassert>
#include <cstring>
#define ll long long
#define ld long double
#define PI acos(-1)
#define oo 1e9
#define rep (i == x ? '\n' : ' ')
#define MEDO_journey_TO_ICPC cin.tie(0);std :: ios :: sync_with_stdio (false);

//ll di[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
//ll dj[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

//ll gcd(ll first, ll second) { return !second ? first : gcd(second, first % second); }
//ll lcm(ll first, ll second) { return (first / gcd(first, second)) * second; }

using namespace std;

ll x, y;
bool b = 1;
deque<ll>q, v;
map<ll, ll>p;

int main(){

	MEDO_journey_TO_ICPC;

	cin >> x;

	for (int i = 0; i < x; i++){
		cin >> y;
		q.push_back(y);
		if (y == 0 && b){
			p[0] = i;
			b = 0;
		}
	}
	for (int i = 0; i < x; i++){
		if (q[i] == 0){
			v.push_back(0);
			p[0] = i;
		}
		else{
			if (i + 1 < x && q[i + 1] == 0){
				v.push_back(1);
				continue;
			}
			if (i + 2 < x && q[i + 2] == 0){
				v.push_back(min((ll)2, abs(i - p[0])));
				continue;
			}
			if (i + 3 < x && q[i + 3] == 0){
				v.push_back(min((ll)3, abs(i - p[0])));
				continue;
			}
			v.push_back(abs(i - p[0]));
		}
	}
	while (!v.empty()){
		cout << v.front() << " ";
		v.pop_front();
	}
	cout << endl;
	return 0;
}


//Author:Medo king
//Created For : Div 2 Round #484
//ان الله لا يضيع اجر من احسن عملا
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <hash_map>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <math.h>
#include <cassert>
#include <cstring>
#define ll long long
#define ld long double
#define PI acos(-1)
#define oo 1e9
#define rep (i == x ? '\n' : ' ')
#define MEDO_journey_TO_ICPC cin.tie(0);std :: ios :: sync_with_stdio (false);

//ll di[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
//ll dj[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

//ll gcd(ll first, ll second) { return !second ? first : gcd(second, first % second); }
//ll lcm(ll first, ll second) { return (first / gcd(first, second)) * second; }

using namespace std;

ll x, y, z = 0;
deque<ll>q, v;
map<ll, vector<ll>>p;

int main(){

	MEDO_journey_TO_ICPC;

	cin >> x;

	for (int i = 0; i < x; i++){
		cin >> y;
		q.push_back(y);
		if (y == 0){
			p[0].push_back(i);
			z++;
		}
	}
	if (z == q.size()){
		while (z > 0){
			cout << 0 << " ";
		}
		return cout << endl, 0;
	}
	for (int i = 0; i < x; i++){
		if (q[i] == 0){
			v.push_back(0);
		}
		else{
			ll mini = oo;
			for (int j = 0; j < p[0].size(); j++){
				mini = min(mini, abs(p[0][j] - i));
			}
			v.push_back(mini);
		}
	}
	while (!v.empty()){
		cout << v.front() << " ";
		v.pop_front();
	}
	cout << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    short n;
    cin>>n;
    vector<int>v(n);
    for(int i=0; i<n; i++)
    {
        cin>>v[i];
        if(v[i])
            v[i]=999999;
    }
    for(int i=0; i<n; i++)
    {
        int cnt=1;
        if(v[i]==0)
        {
            for(int j=i+1; j<n; j++)
            {
                if(!v[j])
                    break;
                if(cnt<v[j])
                    v[j]=cnt++;
                else
                    break;
            }
            cnt=1;
            for(int j=i-1; j>-1; j--)
            {
                if(!v[j])
                    break;
                if(cnt<v[j])
                    v[j]=cnt++;
                else
                    break;
            }
        }
    }
    for(int i=0; i<n; i++)
        cout<<v[i]<<" ";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0; i<n; i++)
    {
        cin>>v[i];
        if(v[i])
            v[i]=9999999;
    }
    for(int i=0; i<n; i++)
    {
        int cnt=1;
        if(v[i]==0)
        {
            for(int j=i+1; j<n; j++)
            {
                if(!v[j])
                    break;
                if(cnt<v[j])
                    v[j]=cnt++;
                else
                    break;
            }
            cnt=1;
            for(int j=i-1; j>-1; j--)
            {
                if(!v[j])
                    break;
                if(cnt<v[j])
                    v[j]=cnt++;
                else
                    break;
            }
        }
    }
    for(int i=0; i<n; i++)
        cout<<v[i]<<" ";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    short n;
    cin>>n;
    vector<short>v(n);
    for(int i=0; i<n; i++)
    {
        cin>>v[i];
        if(v[i])
            v[i]=999999;
    }
    for(int i=0; i<n; i++)
    {
        short cnt=1;
        if(v[i]==0)
        {
            for(int j=i+1; j<n; j++)
            {
                if(!v[j])
                    break;
                if(cnt<v[j])
                    v[j]=cnt++;
                else
                    break;
            }
            cnt=1;
            for(int j=i-1; j>-1; j--)
            {
                if(!v[j])
                    break;
                if(cnt<v[j])
                    v[j]=cnt++;
                else
                    break;
            }
        }
    }
    for(int i=0; i<n; i++)
        cout<<v[i]<<" ";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0; i<n; i++)
    {
        cin>>v[i];
        if(v[i])
            v[i]=999999;
    }
    for(int i=0; i<n; i++)
    {
        int cnt=1;
        if(v[i]==0)
        {
            for(int j=i+1; j<n; j++)
            {
                if(!v[j])
                    break;
                if(cnt<v[j])
                    v[j]=cnt++;
                else
                    break;
            }
            cnt=1;
            for(int j=i-1; j>-1; j--)
            {
                if(!v[j])
                    break;
                if(cnt<v[j])
                    v[j]=cnt++;
                else
                    break;
            }
        }
    }
    for(int i=0; i<n; i++)
        cout<<v[i]<<" ";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    short n;
    cin>>n;
    vector<int>v(n);
    for(int i=0; i<n; i++)
    {
        cin>>v[i];
        if(v[i])
            v[i]=999999;
    }
    for(int i=0; i<n; i++)
    {
        short cnt=1;
        if(v[i]==0)
        {
            for(int j=i+1; j<n; j++)
            {
                if(!v[j])
                    break;
                if(cnt<v[j])
                    v[j]=cnt++;
                else
                    break;
            }
            cnt=1;
            for(int j=i-1; j>-1; j--)
            {
                if(!v[j])
                    break;
                if(cnt<v[j])
                    v[j]=cnt++;
                else
                    break;
            }
        }
    }
    for(int i=0; i<n; i++)
        cout<<v[i]<<" ";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n;
    cin>>n;
    vector<int>v(n),ans(n);
    for(int i=0; i<n; i++)
    {
        cin>>v[i];
        if(v[i])
            v[i]=9999999;
    }
    for(int i=0; i<n; i++)
    {
        int cnt=1;
        if(v[i]==0)
        {
            for(int j=i+1; j<n; j++)
            {
                if(!v[j])
                    break;
                if(cnt<v[j])
                    v[j]=cnt++;
                else
                    break;
            }
            cnt=1;
            for(int j=i-1; j>-1; j--)
            {
                if(!v[j])
                    break;
                if(cnt<v[j])
                    v[j]=cnt++;
                else
                    break;
            }
        }
    }
    for(int i=0; i<n; i++)
        cout<<v[i]<<" ";
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define inf 9223372036854775807 + 1
#define MAXN 100010

using namespace std;

long find(vector<long> v,long ind){
	long i,m=abs(ind-v[0]),temp=m;

	for(i=1;i<v.size();i++){
		m=min(m,abs(ind-v[i]));
		if(m==1) return 1;
		if(temp==m) return m;
		temp=m;
	}

	return m;
}

int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    long N,x;

    cin>>N;
    vector<long> v;

    for(long i=0;i<N;i++){
    	cin>>x;
    	if(!x) v.push_back(i);
    }

    for(long j=v[0];j>=0;j--){
    	cout<<j<<" ";
	}

    for(long i=1;i<v.size();i++){
    	for(long j=v[i-1]+1;j<=v[i];j++){
    		cout<<min(v[i]-j,j-v[i-1])<<" ";
		}
    }

	for(long j=1;j<N-v[v.size()-1];j++){
		cout<<j;
		if(j!=N-1) cout<<" ";
	}

	return 0;

}


#include<bits/stdc++.h>
#define ll long long
#define inf 9223372036854775807 + 1
#define MAXN 100010

using namespace std;

long find(vector<long> v,long ind){
	long i,m=abs(ind-v[0]);

	for(i=1;i<v.size();i++) m=min(m,abs(ind-v[i]));

	return m;
}

int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    long i,N;

    cin>>N;
    ll t[N+1];
    vector<long> v;

    for(i=0;i<N;i++){
    	cin>>t[i];
    	if(!t[i]) v.push_back(i);
    }

    for(i=0;i<N;i++){
    	if(!t[i]) cout<<"0";
    	else cout<<find(v,i);

    	if(i!=N-1) cout<<" ";
	}

	return 0;

}


#include<bits/stdc++.h>
#define ll long long
#define inf 9223372036854775807 + 1
#define MAXN 100010

using namespace std;

long find(vector<long> v,long ind){
	long i,m=abs(ind-v[0]),temp=m;

	for(i=1;i<v.size();i++){
		m=min(m,abs(ind-v[i]));
		if(m==1) return 1;
		if(temp==m) return m;
		temp=m;
	}

	return m;
}

int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    long N,x;

    cin>>N;
    bool p[N+1]={0};
    vector<long> v;

    for(long i=0;i<N;i++){
    	cin>>x;
    	p[i]=(x==0);
    	if(!x) v.push_back(i);
    }

    for(long i=0;i<N;i++){
    	if(p[i]) cout<<"0";
    	else cout<<find(v,i);

    	if(i!=N-1) cout<<" ";
	}

	return 0;

}


#include<bits/stdc++.h>
#define ll long long
#define inf 9223372036854775807 + 1
#define MAXN 100010

using namespace std;

long find(vector<long> v,long ind){
	long i,m=abs(ind-v[0]);

	for(i=1;i<v.size();i++){
		m=min(m,abs(ind-v[i]));
		if(m==1) return 1;
	}

	return m;
}

int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    long i,N;

    cin>>N;
    ll t[N+1];
    vector<long> v;

    for(i=0;i<N;i++){
    	cin>>t[i];
    	if(!t[i]) v.push_back(i);
    }

    for(i=0;i<N;i++){
    	if(!t[i]) cout<<"0";
    	else cout<<find(v,i);

    	if(i!=N-1) cout<<" ";
	}

	return 0;

}


#include<bits/stdc++.h>
#define ll long long
#define inf 9223372036854775807 + 1
#define MAXN 100010

using namespace std;

long find(ll* t,long N,long i){
	long a=i,b=i;

	while(t[a]&&t[b]){
		if(a<N-1) a++;
		if(b>0) b--;
	}

	return abs(a-i);
}

int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    long i,N;

    cin>>N;
    ll t[N+1];

    for(i=0;i<N;i++) cin>>t[i];

    for(i=0;i<N;i++){
    	if(!t[i]) cout<<"0";
    	else cout<<find(t,N,i);

    	if(i!=N-1) cout<<" ";
	}

	return 0;

}


#include<bits/stdc++.h>
#define ll long long
#define inf 9223372036854775807 + 1
#define MAXN 100010

using namespace std;

long find(ll* t,long N,long i){
	long a=i,b=i;

	while((t[a]||a>=N)&&(t[b]||b<0)){
		a++;
		b--;
	}

	if(!t[a]) return abs(a-i);
	return abs(b-i);
}

int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    long i,N;

    cin>>N;
    ll t[N+1];

    for(i=0;i<N;i++) cin>>t[i];

    for(i=0;i<N;i++){
    	if(!t[i]) cout<<"0";
    	else cout<<find(t,N,i);

    	if(i!=N-1) cout<<" ";
	}

	return 0;

}


#include<bits/stdc++.h>
#define ll long long
#define inf 9223372036854775807 + 1
#define MAXN 100010

using namespace std;

long find(vector<long> v,long ind){
	long i,m=abs(ind-v[0]),temp=m;

	for(i=1;i<v.size();i++){
		m=min(m,abs(ind-v[i]));
		if(m==1) return 1;
		if(temp==m) return m;
		temp=m;
	}

	return m;
}

int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    long N,x;

    cin>>N;
    vector<long> v;

    for(long i=0;i<N;i++){
    	cin>>x;
    	if(!x) v.push_back(i);
    }

    for(long j=v[0];j>=0;j--){
    	cout<<j<<" ";
	}

    for(long i=1;i<=v.size();i++){
    	for(long j=v[i-1]+1;j<=v[i];j++){
    		cout<<min(v[i]-j,j-v[i-1])<<" ";
		}
    }

	for(long j=1;j<N-v[v.size()-1];j++){
		cout<<j;
		if(j!=N-1) cout<<" ";
	}

	return 0;

}


#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef vector<vi> vvi;
const int MOD = 1e9 + 7;

#define fastIO \
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define pb push_back
#define ff first
#define ss second
#define mp make_pair

#ifdef DIV_DEBUG
#define cerr(...) __cerr(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __cerr(const char *name, Arg1 &&arg1) {
    cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __cerr(const char *names, Arg1 &&arg1, Args&&... args) {
    const char *sep = strchr(names + 1, ',');
    cerr.write(names, sep - names) << " = " << arg1 << " |";
    __cerr(sep + 1, args...);
}
#else
#define cerr(...)
#endif

int main() {
    fastIO;
    int n, k;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
    	cin>>a[i];
    }
    vi lgt(n,INT_MAX), rgt(n,INT_MAX);
    for(int i=0;i<n;i++){
    	if(a[i]==0)
    		lgt[i] = 0;
    	else if(i>0){
    		lgt[i] = lgt[i-1] + 1;
    	}
    }
    for(int i=n-1;i>=0;i--){
    	if(a[i]==0)
    		rgt[i] = 0;
    	else if (i<=n-2){
    		rgt[i] = rgt[i+1] + 1;
    	}
    }

    for(int i=0;i<n;i++){
    	cout<<min(lgt[i],rgt[i])<<" ";
    }
    return 0;
}


#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef vector<vi> vvi;
const int MOD = 1e9 + 7;

#define fastIO \
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define pb push_back
#define ff first
#define ss second
#define mp make_pair

#ifdef DIV_DEBUG
#define cerr(...) __cerr(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __cerr(const char *name, Arg1 &&arg1) {
    cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __cerr(const char *names, Arg1 &&arg1, Args&&... args) {
    const char *sep = strchr(names + 1, ',');
    cerr.write(names, sep - names) << " = " << arg1 << " |";
    __cerr(sep + 1, args...);
}
#else
#define cerr(...)
#endif

int main() {
    fastIO;
    int n, k;
    cin>>n;
    int a[n];
    int ff = -1, ll;
    for(int i=0;i<n;i++){
    	cin>>a[i];
    	if(a[i]==0){
    		ll = i;
    		if(ff == -1)
    			ff = i;
    	}
    }
    vi lgt(n,INT_MAX), rgt(n,INT_MAX);
    for(int i=ff;i<n;i++){
    	if(a[i]==0)
    		lgt[i] = 0;
    	else if(i>0){
    		lgt[i] = lgt[i-1] + 1;
    	}
    }
    for(int i=ll;i>=0;i--){
    	if(a[i]==0)
    		rgt[i] = 0;
    	else if (i<n-2){
    		rgt[i] = rgt[i+1] + 1;
    	}
    }

    for(int i=0;i<n;i++){
    	cout<<min(lgt[i],rgt[i])<<" ";
    }
    return 0;
}


#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef vector<vi> vvi;
const int MOD = 1e9 + 7;

#define fastIO \
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define pb push_back
#define ff first
#define ss second
#define mp make_pair

#ifdef DIV_DEBUG
#define cerr(...) __cerr(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __cerr(const char *name, Arg1 &&arg1) {
    cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __cerr(const char *names, Arg1 &&arg1, Args&&... args) {
    const char *sep = strchr(names + 1, ',');
    cerr.write(names, sep - names) << " = " << arg1 << " |";
    __cerr(sep + 1, args...);
}
#else
#define cerr(...)
#endif

int main() {
    fastIO;
    int n, k;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    	cin>>a[i];
    vi lgt(n,INT_MAX), rgt(n,INT_MAX);
    for(int i=0;i<n;i++){
    	if(a[i]==0)
    		lgt[i] = 0;
    	else if(i>0 && lgt[i-1]!= INT_MAX){
    		lgt[i] = lgt[i-1] + 1;
    	}
    }
    for(int i=n-1;i>=0;i--){
    	if(a[i]==0)
    		rgt[i] = 0;
    	else if (i<n-2 && rgt[i+1] != INT_MAX){
    		rgt[i] = rgt[i+1] + 1;
    	}
    }

    for(int i=0;i<n;i++){
    	cout<<min(lgt[i],rgt[i])<<" ";
    }
    return 0;
}


#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef vector<vi> vvi;
const int MOD = 1e9 + 7;

#define fastIO \
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define pb push_back
#define ff first
#define ss second
#define mp make_pair

#ifdef DIV_DEBUG
#define cerr(...) __cerr(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __cerr(const char *name, Arg1 &&arg1) {
    cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __cerr(const char *names, Arg1 &&arg1, Args&&... args) {
    const char *sep = strchr(names + 1, ',');
    cerr.write(names, sep - names) << " = " << arg1 << " |";
    __cerr(sep + 1, args...);
}
#else
#define cerr(...)
#endif

int main() {
    fastIO;
    int n, k;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    	cin>>a[i];
    vi lgt(n,INT_MAX), rgt(n,INT_MAX);
    for(int i=0;i<n;i++){
    	if(a[i]==0)
    		lgt[i] = 0;
    	else if(i>0){
    		lgt[i] = lgt[i-1] + 1;
    	}
    }
    for(int i=n-1;i>=0;i--){
    	if(a[i]==0)
    		rgt[i] = 0;
    	else if (i<n-2){
    		rgt[i] = rgt[i+1] + 1;
    	}
    }

    for(int i=0;i<n;i++){
    	cout<<min(lgt[i],rgt[i])<<" ";
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <stdio.h>

using namespace std;

typedef long long ll;

int main()
{
    int n;
    scanf("%i", &n);
    vector <ll> a(n);
    for(int i = 0; i < n; i++)
        cin >> a[i];
    int d0 = 0, dn = 0;
    while(a[d0] != 0)
        d0++;
    printf("%i ", d0);
    while(a[n - dn - 1] != 0)
        dn++;
    for(int i = 1; i < n - 1; i++){
        int p1 = i, p2 = i;
        while((a[p1] != 0) && (a[p2] != 0) && (p1 >= 0) && (p2 <= n - 1))
            p1--;
            p2++;
        if((!a[p1]) && (!a[p2]))
            printf("%i ", min(i - p1, p2 - i));
        else if(!a[p1])
            printf("%i ", i - p1);
        else
            printf("%i ", p2 - i);
    }
    printf("%i ", dn);

    return 0;
}


#include <cstdlib>
#include <vector>
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector <int> a(n);
	vector <int> pos0;
	for (int i = 0; i < n; i++){
		cin >> a[i];
		if (a[i] == 0)
			pos0.push_back(i);
	}
	for (int i = 0; i < pos0[0]; i++)
		cout << pos0[0] - i << " ";
	for (int i = 0; i < pos0.size() - 1; i++){
		int l = pos0[i + 1] - pos0[i];
		for (int j = 0; j < l; j++)
			cout << min(j, l - j) << " ";
	}
	for (int i = 0; i <= a.size() - pos0[pos0.size() - 1] - 1; i++)
		cout << i << " ";
	return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <stdio.h>

using namespace std;

typedef long long ll;

int main()
{
    int n;
    scanf("%i", &n);
    vector <ll> a(n);
    for(int i = 0; i < n; i++)
        cin >> a[i];
    int d0 = 0, dn = 0;
    while(a[d0] != 0)
        d0++;
    printf("%i ", d0);
    while(a[n - dn - 1] != 0)
        dn++;
    for(int i = 1; i < n - 1; i++){
        int p1 = i, p2 = i;
        while((p1 > 0) && (p2 < n - 1) && (a[p1] != 0) && (a[p2] != 0))
            p1--;
            p2++;
        if((!a[p1]) && (!a[p2]))
            printf("%i ", min(i - p1, p2 - i));
        else if(!a[p1])
            printf("%i ", i - p1);
        else
            printf("%i ", p2 - i);
    }
    printf("%i ", dn);

    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <stdio.h>

using namespace std;

typedef long long ll;

int main()
{
    int n;
    scanf("%i", &n);
    if(n == 1){
        cout << 0;
        return 0;
    }
    vector <ll> a(n);
    for(int i = 0; i < n; i++)
        cin >> a[i];
    int d0 = 0, dn = 0;
    while(a[d0] != 0)
        d0++;
    printf("%i ", d0);
    while(a[n - dn - 1] != 0)
        dn++;
    for(int i = 1; i < n - 1; i++){
        int p1 = i, p2 = i;
        while((p1 > 0) && (p2 < n - 1) && (a[p1] != 0) && (a[p2] != 0))
            p1--;
            p2++;
        if((!a[p1]) && (!a[p2]))
            printf("%i ", min(i - p1, p2 - i));
        else if(!a[p1])
            printf("%i ", i - p1);
        else
            printf("%i ", p2 - i);
    }
    printf("%i ", dn);

    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <stdio.h>

using namespace std;

typedef long long ll;

int main()
{
    int n;
    scanf("%i", &n);
    if(n == 1){
        cout << 0;
        return 0;
    }
    vector <ll> a(n);
    for(int i = 0; i < n; i++)
        cin >> a[i];
    int d0 = 0, dn = 0;
    while(a[d0] != 0)
        d0++;
    printf("%i ", d0);
    while(a[n - dn - 1] != 0)
        dn++;
    for(int i = 1; i < n - 1; i++){
        int p1 = i, p2 = i;
        while((p1 > 0) && (p2 < n - 1) && (a[p1] != 0) && (a[p2] != 0))
            p1--;
            p2++;
        if(a[p1] == 0 && a[p2] == 0)
            printf("%i ", min(i - p1, p2 - i));
        else if(a[p1] == 0)
            printf("%i ", i - p1);
        else
            printf("%i ", p2 - i);
    }
    printf("%i ", dn);

    return 0;
}