/*
ID: henrybu2
LANG: C++
PROB: dualpal
*/

#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <sstream>
#include <iomanip>
#include <stack>
#include <fstream>
#include <algorithm>
#include <set>
#include <iterator>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <map>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
using namespace std;

#include <iostream>
#include <fstream>
using namespace std;

vector<int> numbers;

int main()
{
	IOS;

	//freopen("lemonade.in", "r", stdin);
	//freopen("lemonade.out", "w", stdout);

	int N; cin >> N;

	for (int i = 0; i < N; ++i)
	{
		int x; cin >> x;
		vector<int> temp;
		for (int j = 0; j < x; ++j)
		{
			int y; cin >> y;
			temp.push_back(y);
		}

		sort(temp.begin(), temp.end());

		int mid = x / 2 - 1;

		cout << temp[mid] << " ";

		for (int a = mid + 1; a < temp.size(); ++a)
		{
			cout << temp[a] << " ";
		}

		for (int b = mid - 1; b >= 0; --b)
		{
			cout << temp[b] << " ";
		}

		cout << endl;

	}

}


/*
ID: henrybu2
LANG: C++
PROB: dualpal
*/

#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <sstream>
#include <iomanip>
#include <stack>
#include <fstream>
#include <algorithm>
#include <set>
#include <iterator>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <map>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
using namespace std;

#include <iostream>
#include <fstream>
using namespace std;

vector<int> numbers;

int main()
{
	IOS;

	//freopen("lemonade.in", "r", stdin);
	//freopen("lemonade.out", "w", stdout);

	int N; cin >> N;

	for (int i = 0; i < N; ++i)
	{
		int x; cin >> x;
		vector<int> temp;
		for (int j = 0; j < x; ++j)
		{
			int y; cin >> y;
			temp.push_back(y);
		}

		sort(temp.begin(), temp.end());

		int mid;
		if (x % 2 != 0) mid = x / 2;
		else
		{
			mid = x / 2 - 1;
		}

		cout << temp[mid] << " ";

		for (int a = mid + 1; a < temp.size(); ++a)
		{
			cout << temp[a] << " ";
		}

		for (int b = mid - 1; b >= 0; --b)
		{
			cout << temp[b] << " ";
		}

		cout << endl;

	}

}


/*
ID: henrybu2
LANG: C++
PROB: dualpal
*/

#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <sstream>
#include <iomanip>
#include <stack>
#include <fstream>
#include <algorithm>
#include <set>
#include <iterator>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <map>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
using namespace std;

#include <iostream>
#include <fstream>
using namespace std;

vector<int> numbers;

int main()
{
	IOS;

	//freopen("lemonade.in", "r", stdin);
	//freopen("lemonade.out", "w", stdout);

	int N; cin >> N;

	for (int i = 0; i < N; ++i)
	{
		int x; cin >> x;
		vector<int> temp;
		for (int j = 0; j < x; ++j)
		{
			int y; cin >> y;
			temp.push_back(y);
		}

		sort(temp.begin(), temp.end());

		int mid;
		if (x % 2 != 0) mid = x / 2;
		else
		{
			mid = x / 2 - 1;
		}

		cout << temp[mid] << " ";

		int a = mid + 1;
		int b = mid - 1;

		while (true)
		{
			if (a < temp.size())
			{
				cout << temp[a] << " ";
				a++;
			}

			if (b >= 0)
			{
				cout << temp[b] << " ";
				b--;
			}

			if(b < 0 && a >= temp.size())
			{
				break;
			}
		}

		cout << endl;

	}

}


/*
ID: henrybu2
LANG: C++
PROB: dualpal
*/

#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <sstream>
#include <iomanip>
#include <stack>
#include <fstream>
#include <algorithm>
#include <set>
#include <iterator>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <map>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
using namespace std;

#include <iostream>
#include <fstream>
using namespace std;

vector<int> numbers;

int main()
{
	IOS;

	//freopen("lemonade.in", "r", stdin);
	//freopen("lemonade.out", "w", stdout);

	int N; cin >> N;

	for (int i = 0; i < N; ++i)
	{
		int x; cin >> x;
		vector<int> temp;
		for (int j = 0; j < x; ++j)
		{
			int y; cin >> y;
			temp.push_back(y);
		}

		sort(temp.begin(), temp.end());

		int mid;
		if (x % 2 != 0) mid = x / 2;
		else
		{
			mid = x / 2 - 1;
		}

		cout << temp[mid] << " ";

		int a = x + 1;
		int b = x - 1;

		while (true)
		{
			if (a < temp.size())
			{
				cout << temp[a] << " ";
				a++;
			}

			if (b >= 0)
			{
				cout << temp[b];
				b--;
			}

			if(b < 0 && a >= temp.size())
			{
				break;
			}
		}

		cout << endl;

	}

}


/*
ID: henrybu2
LANG: C++
PROB: dualpal
*/

#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <sstream>
#include <iomanip>
#include <stack>
#include <fstream>
#include <algorithm>
#include <set>
#include <iterator>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <map>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
using namespace std;

#include <iostream>
#include <fstream>
using namespace std;

vector<int> numbers;

int main()
{
	IOS;

	//freopen("lemonade.in", "r", stdin);
	//freopen("lemonade.out", "w", stdout);

	int N; cin >> N;

	for (int i = 0; i < N; ++i)
	{
		int x; cin >> x;
		vector<int> temp;
		for (int j = 0; j < x; ++j)
		{
			int y; cin >> y;
			temp.push_back(y);
		}

		sort(temp.begin(), temp.end());

		int mid = x / 2 + 1;

		cout << temp[mid] << " ";

		for (int a = mid + 1; a < temp.size(); ++a)
		{
			cout << temp[a] << " ";
		}

		for (int b = mid - 1; b >= 0; --b)
		{
			cout << temp[b] << " ";
		}

		cout << endl;

	}

}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define ZERO_IQ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x, y) cout<<(#x)<<" " <<(#y)<<" is " << (x) <<" "<< (y) << endl
#define debug2(x, y, z) cout<<(#x)<<" " <<(#y)<<" " <<(#z)<<" is " << (x) <<" "<< (y) <<" "<<(z) << endl
#define watch(x) cout<<(#x)<<" is " << (x) << endl

ll const N = 3 * 1e5 + 2;

int main() {
    ZERO_IQ
    ll n;
    cin >> n;
    while (n--) {
        ll a;
        cin >> a;
        vector<ll> v(a);
        for (int i = 0; i < a; ++i) {
            cin >> v[i];
        }
        sort(v.begin(), v.end());
        ll minn = 9e18, first = 0, second = 1;
        for (int j = 0; j < v.size() - 1; ++j) {
            if (abs(v[j] - v[j + 1]) < minn) {
                minn = abs(v[j] - v[j + 1]);
                first = j;
                second = j + 1;
            }
        }
        ll first2 = first, second2 = second;
        vector<ll> ans, ans2;
        ans.push_back(v[first]);
        ans.push_back(v[second]);
        ans2.push_back(v[second]);
        ans2.push_back(v[first]);
        while (true) {
            if (second + 1 < v.size() && first - 1 >= 0 &&
                abs(ans.back() - v[second + 1]) < abs(ans.back() - v[first - 1])) {
                ans.push_back(v[second + 1]);
                second++;
            } else if (first - 1 >= 0) {
                ans.push_back(v[first - 1]);
                first--;
            } else if (second + 1 < v.size()) {
                ans.push_back(v[second + 1]);
                second++;
            }
            if (second + 1 == v.size() && first - 1 < 0)break;
        }
        while (true) {
            if (second2 + 1 < v.size() && first2 - 1 >= 0 &&
                abs(ans2.back() - v[second2 + 1]) < abs(ans2.back() - v[first2 - 1])) {
                ans2.push_back(v[second2 + 1]);
                second2++;
            } else if (first2 - 1 >= 0) {
                ans2.push_back(v[first2 - 1]);
                first2--;
            } else if (second2 + 1 < v.size()) {
                ans2.push_back(v[second2 + 1]);
                second2++;
            }
            if (second2 + 1 == v.size() && first2 - 1 < 0)break;
        }
        ll qq = 0;
        for (int k = 0; k < ans.size() - 1; ++k) {
            if (abs(ans[k] - ans[k + 1]) >= qq) {
                qq = abs(ans[k] - ans[k + 1]);
            } else {
                qq = -1;
                break;
            }
        }
        if (qq == -1) {
            for (auto i:ans2)cout << i << " ";
        } else for (auto i:ans)cout << i << " ";
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define ZERO_IQ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x, y) cout<<(#x)<<" " <<(#y)<<" is " << (x) <<" "<< (y) << endl
#define debug2(x, y, z) cout<<(#x)<<" " <<(#y)<<" " <<(#z)<<" is " << (x) <<" "<< (y) <<" "<<(z) << endl
#define watch(x) cout<<(#x)<<" is " << (x) << endl

ll const N = 3 * 1e5 + 2;

int main() {
    ZERO_IQ
    ll n;
    cin >> n;
    while (n--) {
        ll a;
        cin >> a;
        vector<ll> v(a);
        for (int i = 0; i < a; ++i) {
            cin >> v[i];
        }
        sort(v.begin(), v.end());
        cout << v[ceil((double) v.size() / 2.0) - 1] << " " << v[ceil((double) v.size() / 2.0)] << " ";
        ll first = ceil((double) v.size() / 2.0) - 2;
        ll second = ceil((double) v.size() / 2.0) + 1;
        ll c = 0, j, jj;
        for (j = first, jj = second; j >= 0 && jj < v.size(); --j, jj++) {
            cout << v[j] << " " << v[jj] << " ";
        }
        if (j >= 0)cout << v[j] << " ";
        else if (jj < v.size())cout << v[jj] << " ";
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define ZERO_IQ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x, y) cout<<(#x)<<" " <<(#y)<<" is " << (x) <<" "<< (y) << endl
#define debug2(x, y, z) cout<<(#x)<<" " <<(#y)<<" " <<(#z)<<" is " << (x) <<" "<< (y) <<" "<<(z) << endl
#define watch(x) cout<<(#x)<<" is " << (x) << endl

ll const N = 3 * 1e5 + 2;

int main() {
    ZERO_IQ
    ll n;
    cin >> n;
    while (n--) {
        ll a;
        cin >> a;
        vector<ll> v(a);
        for (int i = 0; i < a; ++i) {
            cin >> v[i];
        }
        sort(v.begin(), v.end());
        cout << v[v.size() / 2 - 1] << " " << v[v.size() / 2] << " ";
        ll first = v.size() / 2 - 1;
        ll second = v.size() / 2;
        ll c = 0;
        while (true) {
            if (!c && first - 1 >= 0) {
                cout << v[first - 1] << " ";
                first--;
                c = 1;
            } else if (second + 1 < v.size() && c) {
                cout << v[second + 1] << " ";
                second++;
                c = 0;
            } else if (second + 1 < v.size() && !c) {
                cout << v[second + 1] << " ";
                second++;
                c=1;
            } else if (c && first - 1 >= 0) {
                cout << v[first - 1] << " ";
                first--;
                c=0;
            } else break;
        }
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define ZERO_IQ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x, y) cout<<(#x)<<" " <<(#y)<<" is " << (x) <<" "<< (y) << endl
#define debug2(x, y, z) cout<<(#x)<<" " <<(#y)<<" " <<(#z)<<" is " << (x) <<" "<< (y) <<" "<<(z) << endl
#define watch(x) cout<<(#x)<<" is " << (x) << endl

ll const N = 3 * 1e5 + 2;

int main() {
    ZERO_IQ
    ll n;
    cin >> n;
    while (n--) {
        ll a;
        cin >> a;
        vector<ll> v(a);
        for (int i = 0; i < a; ++i) {
            cin >> v[i];
        }
        sort(v.begin(), v.end());
        cout << v[v.size() / 2 - 1] << " " << v[v.size() / 2]<<" ";
        ll first = v.size() / 2 - 1;
        ll second = v.size() / 2;
        ll c = 0;
        while (true) {
            if (!c && first - 1 >= 0) {
                cout << v[first - 1] << " ";
                first--;
                c = 1;
            } else if (second + 1 < v.size() && c) {
                cout << v[second + 1] << " ";
                second++;
                c = 0;
            }
            else break;
        }
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define ZERO_IQ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x, y) cout<<(#x)<<" " <<(#y)<<" is " << (x) <<" "<< (y) << endl
#define debug2(x, y, z) cout<<(#x)<<" " <<(#y)<<" " <<(#z)<<" is " << (x) <<" "<< (y) <<" "<<(z) << endl
#define watch(x) cout<<(#x)<<" is " << (x) << endl

ll const N = 3 * 1e5 + 2;

int main() {
    ZERO_IQ
    ll n;
    cin >> n;
    while (n--) {
        ll a;
        cin >> a;
        vector<ll> v(a);
        for (int i = 0; i < a; ++i) {
            cin >> v[i];
        }
        sort(v.begin(), v.end());
        ll minn = 9e18, first = 0, second = 1;
        for (int j = 0; j < v.size() - 1; ++j) {
            if (abs(v[j] - v[j + 1]) < minn) {
                minn = abs(v[j] - v[j + 1]);
                first = j;
                second = j + 1;
            }
        }
        vector<ll> ans;
        ans.push_back(v[first]);
        ans.push_back(v[second]);
        while (true) {
            if (second + 1 < v.size() && first - 1 >= 0 &&
                abs(ans.back() - v[second + 1]) < abs(ans.back() - v[first - 1])) {
                ans.push_back(v[second + 1]);
                second++;
            } else if (first - 1 >= 0) {
                ans.push_back(v[first - 1]);
                first--;
            } else if (second + 1 < v.size() && second) {
                ans.push_back(v[second + 1]);
                second++;
            }
            if(second + 1==v.size()&&first - 1 < 0)break;
        }
        for (auto i : ans)cout << i << " ";
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define ZERO_IQ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x, y) cout<<(#x)<<" " <<(#y)<<" is " << (x) <<" "<< (y) << endl
#define debug2(x, y, z) cout<<(#x)<<" " <<(#y)<<" " <<(#z)<<" is " << (x) <<" "<< (y) <<" "<<(z) << endl
#define watch(x) cout<<(#x)<<" is " << (x) << endl

ll const N = 3 * 1e5 + 2;

int main() {
    ZERO_IQ
    ll n;
    cin >> n;
    while (n--) {
        ll a;
        cin >> a;
        vector<ll> v(a);
        for (int i = 0; i < a; ++i) {
            cin >> v[i];
        }
        sort(v.begin(), v.end());
        ll minn = 9e18, first = 0, second = 1;
        for (int j = 0; j < v.size() - 1; ++j) {
            if (abs(v[j] - v[j + 1]) < minn) {
                minn = abs(v[j] - v[j + 1]);
                first = j;
                second = j + 1;
            }
        }
        vector<ll> ans;
        ans.push_back(v[first]);
        ans.push_back(v[second]);
        for (int k = second + 1; k < v.size(); ++k) {
            ans.push_back(v[k]);
        }
        for (int k = first - 1; k >= 0; --k) {
            ans.push_back(v[k]);
        }
        for (auto i : ans)cout << i << " ";
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define ZERO_IQ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x, y) cout<<(#x)<<" " <<(#y)<<" is " << (x) <<" "<< (y) << endl
#define debug2(x, y, z) cout<<(#x)<<" " <<(#y)<<" " <<(#z)<<" is " << (x) <<" "<< (y) <<" "<<(z) << endl
#define watch(x) cout<<(#x)<<" is " << (x) << endl

ll const N = 3 * 1e5 + 2;

int main() {
    ZERO_IQ
    ll n;
    cin >> n;
    while (n--) {
        ll a;
        cin >> a;
        vector<ll> v(a);
        for (int i = 0; i < a; ++i) {
            cin >> v[i];
        }
        sort(v.begin(), v.end());
        cout << v[v.size() / 2 - 1] << " " << v[v.size() / 2] << " ";
        ll first = v.size() / 2 - 1;
        ll second = v.size() / 2;
        ll c = 0;
        while (true) {
            if (!c && first - 1 >= 0) {
                cout << v[first - 1] << " ";
                first--;
                c = 1;
            } else if (second + 1 < v.size() && c) {
                cout << v[second + 1] << " ";
                second++;
                c = 0;
            } else if (second + 1 < v.size() && !c) {
                cout << v[second + 1] << " ";
                second++;
            } else if (c && first - 1 >= 0) {
                cout << v[first - 1] << " ";
                first--;
            } else break;
        }
        cout << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back;
#define all(x) x.begin(),x.end()
using namespace std;

int main()
{
  ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
  int t;
  cin>>t;
  while(t--)
  {
    int n;
    cin>>n;
    vector<ll>v(n);
    for(auto &x:v)
    cin>>x;

    sort(all(v));

    int cur=1,l,r;
    ll md = 1e12;
    for(int i=1;i<n;i++)
    {
       if(abs(v[i]-v[i-1])<md)
       {
         cur = i;
         l=i-2;
         r=i+1;
         md = abs(v[i]-v[i-1]);
       }
    }

   cout<<v[cur-1]<<" "<<v[cur]<<" ";

   int k=2;
   while(k<n)
   {
     ll d1,d2;
      d1=d2=1e15;
      if(l>=0)
      d1 = abs(v[cur]-v[l]);
      if(r<n)
      d2 = abs(v[cur]-v[r]);
     if(l>=0 && d1<=d2)
     {
       cout<<v[l]<<" ";
       l--;
     }
     else
     {
       cout<<v[r]<<" ";
       r++;
     }
     k++;
   }
   cout<<endl;
  }
  return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back;
#define all(x) x.begin(),x.end()
using namespace std;

int main()
{
  ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
  int t;
  cin>>t;
  while(t--)
  {
    int n;
    cin>>n;
    vector<ll>v(n);
    for(auto &x:v)
    cin>>x;

    sort(all(v));
    int i;
    if(n%2==0)
    i=n/2-1;
    else
    i=n/2;
    int j=i+1;
    int k=0;
    while(i>=0 && j<n)
    {
      if(k%2==0)
      cout<<v[i]<<" ",i--;
      else
      cout<<v[j]<<" ",j++;
      k++;
    }
    if(i>=0)
    cout<<v[i];
    if(j<n)
    cout<<v[j];
    cout<<endl;

  }
  return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back;
#define all(x) x.begin(),x.end()
using namespace std;

int main()
{
  ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
  int t;
  cin>>t;
  while(t--)
  {
    int n;
    cin>>n;
    vector<ll>v(n);
    for(auto &x:v)
    cin>>x;

    sort(all(v));

    int cur=1,l,r;
    ll md = 1e12;
    for(int i=1;i<n;i++)
    {
       if(abs(v[i]-v[i-1])<md)
       {
         cur = i;
         l=i-2;
         r=i+1;
         md = abs(v[i]-v[i-1]);
       }
    }

   cout<<v[cur-1]<<" "<<v[cur]<<" ";

   int k=2;
   while(k<n)
   {
     ll d1,d2;
     d1=d2=1e12;
      if(l>=0)
      d1 = abs(v[cur]-v[l]);
      if(r<n)
      d2 = abs(v[cur]-v[r]);
     if(d1<=d2)
     {
       cout<<v[l]<<" ";
       l--;
     }
     else
     {
       cout<<v[r]<<" ";
       r++;
     }
     k++;
   }
   cout<<endl;
  }
  return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back;
#define all(x) x.begin(),x.end()
using namespace std;

int main()
{
  ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
  int t;
  cin>>t;
  while(t--)
  {
    int n;
    cin>>n;
    vector<ll>v(n);
    for(auto &x:v)
    cin>>x;

    sort(all(v));
    int i=n/2-1;
    int j=i+1;
    int k=0;
    while(i>=0 && j<n)
    {
      if(k%2==0)
      cout<<v[i]<<" ",i--;
      else
      cout<<v[j]<<" ",j++;
      k++;
    }
    if(i>=0)
    cout<<v[i];
    if(j<n)
    cout<<v[j];
    cout<<endl;

  }
  return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back;
#define all(x) x.begin(),x.end()
using namespace std;

int main()
{
  ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
  int t;
  cin>>t;
  while(t--)
  {
    int n;
    cin>>n;
    vector<ll>v(n);
    for(auto &x:v)
    cin>>x;

    sort(all(v));

    int cur=1,l,r;
    ll md = 1e12;
    for(int i=1;i<n;i++)
    {
       if(abs(v[i]-v[i-1])<md)
       {
         cur = i;
         l=i-2;
         r=i+1;
         md = abs(v[i]-v[i-1]);
       }
    }

   cout<<v[cur-1]<<" "<<v[cur]<<" ";

   int k=2;
   while(k<n)
   {
     ll d1,d2;
      d1=d2=1e15;
      if(l>=0)
      d1 = abs(v[cur]-v[l]);
      if(r<n)
      d2 = abs(v[cur]-v[r]);
     if(d1<=d2)
     {
       cout<<v[l]<<" ";
       cur = l;
       l--;
     }
     else
     {
       cout<<v[r]<<" ";
       cur = r;
       r++;
     }
     k++;
   }
   cout<<endl;
  }
  return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back;
#define all(x) x.begin(),x.end()
using namespace std;

int main()
{
  ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
  int t;
  cin>>t;
  while(t--)
  {
    int n;
    cin>>n;
    vector<int>v(n);
    for(auto &x:v)
    cin>>x;

    sort(all(v));

    int cur=1,l,r;
    ll md = 1e12;
    for(int i=1;i<n;i++)
    {
       if(abs(v[i]-v[i-1])<md)
       {
         cur = i;
         l=i-2;
         r=i+1;
         md = abs(v[i]-v[i-1]);
       }
    }

   cout<<v[cur-1]<<" "<<v[cur]<<" ";

   int k=2;
   while(k<n)
   {
     ll d1,d2;
     d1=d2=1e12;
      if(l>=0)
      d1 = abs(v[cur]-v[l]);
      if(r<n)
      d2 = abs(v[cur]-v[r]);
     if(d1<=d2)
     {
       cout<<v[l]<<" ";
       l--;
     }
     else
     {
       cout<<v[r]<<" ";
       r++;
     }
     k++;
   }
   cout<<endl;
  }
  return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back;
#define all(x) x.begin(),x.end()
using namespace std;

int main()
{
  ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
  int t;
  cin>>t;
  while(t--)
  {
    int n;
    cin>>n;
    vector<int>v(n);
    for(auto &x:v)
    cin>>x;

    sort(all(v));

    int cur=1,l,r;
    ll md = INT_MAX;
    for(int i=1;i<n;i++)
    {
       if(abs(v[i]-v[i-1])<md)
       {
         cur = i;
         l=i-2;
         r=i+1;
         md = abs(v[i]-v[i-1]);
       }
    }

   cout<<v[cur-1]<<" "<<v[cur]<<" ";

   int k=2;
   while(k<n)
   {
     int d1,d2;
     d1=d2=INT_MAX;
      if(l>=0)
      d1 = abs(v[cur]-v[l]);
      if(r<n)
      d2 = abs(v[cur]-v[r]);
     if(d1<=d2)
     {
       cout<<v[l]<<" ";
       l--;
     }
     else
     {
       cout<<v[r]<<" ";
       r++;
     }
     k++;
   }
   cout<<endl;
  }
  return 0;
}


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

#define ll long long
#define rep(_i,_a,_n) for(_i=_a;_i<_n;_i++)

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll test_case; cin>>test_case;

    while(test_case--){
        ll n,i; cin>>n;
        ll arr[n];
        rep(i,0,n) cin>>arr[i];
        sort(arr,arr+n);

        ll left(n/2 - 1),right( n/2 );

        while(left >= 0 && right < n){
            if(left >= 0) cout<<arr[left]<<" ";
            if(right < n) cout<<arr[right]<<" ";
            left--;
            right++;
        }

        cout<<"\n";
    }

    return 0;
}


 #include<bits/stdc++.h>
using namespace std;
#define int long long
int getSum(int n)
    {
    int sum = 0;
    while (n != 0)
    {
     sum = sum + n % 10;
     n = n/10;
    }
 return sum;
 }

int32_t main(){
int t;
cin>>t;
while(t--){
	int n,i,len,f=0,g=0,ones;
	cin>>n;
	string s[n];
	for(i=0;i<n;i++){
		cin>>s[i];
		len=s[i].size();
		if(len%2==1)
		f=1;
		ones=getSum(stoi(s[i]));
		if(ones%2!=1)
		g=1;
	}
	if(f==1){
		cout<<n<<'\n';
		continue;
	}
	else if(g==1){
		cout<<n-1<<'\n';
		continue;
	}
	else
	cout<<n<<'\n';
}
return 0;
}


 #include<bits/stdc++.h>
using namespace std;
#define int long long
int getSum(string n)
    {
    int sum = 0;
   for(int i=0;i<n.size();i++)
   if(n[i]=='1')
   sum++;
 return sum;
 }

int32_t main(){
int t;
cin>>t;
while(t--){
	int n,i,len,f=0,g=0,ones;
	cin>>n;
	string s[n];
	for(i=0;i<n;i++){
		cin>>s[i];
		len=s[i].size();
		if(len%2==1)
		f=1;
		ones=getSum(s[i]);
		if(ones%2!=1)
		g=1;
	}
	if(f==1){
		cout<<n<<'\n';
		continue;
	}
	else if(g==1){
		cout<<n-1<<'\n';
		continue;
	}
	else
	cout<<n<<'\n';
}
return 0;
}


 #include<bits/stdc++.h>
using namespace std;
#define int long long
int getSum(string n)
    {
    int sum = 0;
   for(int i=0;i<n.size();i++)
   if(n[i]=='1')
   sum++;
 return sum;
 }

int32_t main(){
int t;
cin>>t;
while(t--){
	int n,i,len,f=0,g=0,ones;
	cin>>n;
	string s[n];
	for(i=0;i<n;i++){
		cin>>s[i];
		len=s[i].size();
		if(len%2==1)
		f=1;
		ones=getSum(s[i]);
		if(ones%2==1)
		g=1;
	}
	if(f==1){
		cout<<n<<'\n';
		continue;
	}
	else if(g==1){
		cout<<n-1<<'\n';
		continue;
	}
	else
	cout<<n<<'\n';
}
return 0;
}


 #include<bits/stdc++.h>
using namespace std;
#define int long long
int getSum(int n)
    {
    int sum = 0;
    while (n != 0)
    {
     sum = sum + n % 10;
     n = n/10;
    }
 return sum;
 }

int32_t main(){
int t;
cin>>t;
while(t--){
	int n,i,len,f=0,g=0,ones;
	cin>>n;
	string s[n];
	for(i=0;i<n;i++){
		cin>>s[i];
		len=s[i].size();
		if(len%2==1)
		f=1;
		ones=getSum(stoi(s[i]));
		if(ones%2==1)
		g=1;
	}
	if(f==1){
		cout<<n<<'\n';
		continue;
	}
	else if(g==1){
		cout<<n-1<<'\n';
		continue;
	}
	else
	cout<<n<<'\n';
}
return 0;
}


 #include<bits/stdc++.h>
using namespace std;
#define int long long
int getSum(int n)
    {
    int sum = 0;
    while (n != 0)
    {
     sum = sum + n % 10;
     n = n/10;
    }
 return sum;
 }

int32_t main(){
int t;
cin>>t;
while(t--){
	int n,i,len,f=0,g=0,ones;
	cin>>n;
	string s[n];
	for(i=0;i<n;i++){
		cin>>s[i];
		len=s[i].size();
		if(len%2==1)
		f=1;
		ones=stoi(s[i]);
		if(ones%2!=1)
		g=1;
	}
	if(f==1){
		cout<<n<<'\n';
		continue;
	}
	else if(g==1){
		cout<<n-1<<'\n';
		continue;
	}
	else
	cout<<n<<'\n';
}
return 0;
}


 #include<bits/stdc++.h>
using namespace std;
#define int long long
int getSum(string n)
    {
    int sum = 0;
   for(int i=0;i<n.size();i++){
   if(n[i]=='1')
   sum++;
   }
 return sum;
 }

int32_t main(){
int t;
cin>>t;
while(t--){
	int n,i,len,f=0,ones=0;
	cin>>n;
	string s[n];
	for(i=0;i<n;i++){
		cin>>s[i];
		len=s[i].size();
		if(len%2==1)
		f=1;
		ones+=getSum(s[i]);
	}
	if(f==1){
		cout<<n<<'\n';
		continue;
	}
	else if(ones%2==1){
		cout<<n-1<<'\n';
		continue;
	}
	else
	cout<<n<<'\n';
}
return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <fstream>

using namespace std;

int main()
{
	long long q;
	cin >> q;
	for (int qi = 0; qi < q; qi++)
	{
		int n;
		cin >> n;
		string ssss;
		getline(cin, ssss);
		int Ones = 0;
		int Zeroes = 0;
		int Evens = 0;
		int lens[50];
		for (int i = 0; i < n; i++)
		{
			string s;
			getline(cin, s);
			for (int si = 0; si <= s.size(); si++)
			{
				if (s[si] == '1')
					Ones++;
				else
					Zeroes++;
			}
			if (s.size() % 2 == 1)
				Evens++;
			lens[i] = s.size();
		}
		int o = (Ones % (n * 2));
		cout << (
			Evens % 2 == 1 ?
				n :
				(Ones % 2 == 0 && Zeroes % 2 == 0 ?
					n :
					n - 1)) << endl;
	}
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <fstream>
#include <map>

using namespace std;

int main()
{
	long long q;
	cin >> q;
	for (int qi = 0; qi < q; qi++)
	{
		int n;
		cin >> n;
		string ssss;
		getline(cin, ssss);
		int Ones = 0;
		int Zeroes = 0;
		int Evens = 0;
		int lens[50];
		for (int i = 0; i < n; i++)
		{
			string s;
			getline(cin, s);
			for (int si = 0; si < s.size(); si++)
			{
				if (s[si] == '1')
					Ones++;
				else
					Zeroes++;
			}
			if (s.size() % 2 == 1)
				Evens++;
			lens[i] = s.size();
		}
		int o = (Ones % (n * 2));
		cout << (
			Evens % 2 == 1 ?
			n :
			(Ones % 2 == 0 && Zeroes % 2 == 0 ?
				n :
				(Evens > 0 ? n : n - 1))) << endl;
	}
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <fstream>

using namespace std;

int main()
{
	long long q;
	cin >> q;
	for (int qi = 0; qi < q; qi++)
	{
		int n;
		cin >> n;
		string ssss;
		getline(cin, ssss);
		int Ones = 0;
		int Zeroes = 0;
		int Evens = 0;
		int lens[50];
		for (int i = 0; i < n; i++)
		{
			string s;
			getline(cin, s);
			for (int si = 0; si <= s.size(); si++)
			{
				if (s[si] == '1')
					Ones++;
				else
					Zeroes++;
			}
			if (s.size() % 2 == 1)
				Evens++;
			lens[i] = s.size();
		}
		int o = (Ones % (n * 2));
		cout << (
			Evens % 2 == 1 ?
				n :
				(Ones % 2 == 0 && Zeroes % 2 == 0 ?
					n :
					(Evens > 0 ? n : n - 1))) << endl;
	}
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<set>

using namespace std;

char s[100];

int main(){
	int T;
	cin>>T;
	while(T--){
		int n ;scanf("%d",&n);
		int wann=0;
		vector<int>Q;
		Q.clear();
		for(int i = 0;i<n;i++){
			scanf("%s",s);
			int len=strlen(s);
			if(len&1) wann++;
			int cnt=0;
			for(int i = 0;i<len/2;i++){
				if(s[i]!=s[len-i-1]) cnt++;
			}
			Q.push_back(cnt);
		}

		sort(Q.begin(),Q.end());
		int res = Q[0];
		int ans = 0;
		for(int i = 1;i<Q.size();i++){
			res = Q[i]-res;
			ans++;
		}
		if(res<=wann) ans++;
		printf("%d\n",ans);
	}
	return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<set>

using namespace std;

char s[100];

int main(){
	int T;
	cin>>T;
	while(T--){
		int n ;scanf("%d",&n);
		int wann=0;
		vector<int>Q;
		Q.clear();
		for(int i = 0;i<n;i++){
			scanf("%s",s);
			int len=strlen(s);
			if(len&1) wann++;
			int cnt=0;
			for(int i = 0;i<len/2;i++){
				if(s[i]!=s[len-i-1]) cnt++;
			}
			Q.push_back(cnt);
		}
		sort(Q.begin(),Q.end());
		int res = Q[0];
		int ans = 0;
		for(int i = 1;i<Q.size();i++){
			res = Q[i]-res;
			ans++;
		}
	//	if(wann>=res)ans++;
		if(wann||(res%2==0)) ans++;
		printf("%d\n",ans);
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<fstream>
#include<queue>
#include<iostream>
#include<unordered_map>
#include<math.h>
#include<stack>
#include <numeric>
#include<iomanip>
#include<unordered_set>
using namespace std;
typedef long long ll;
const int maxn = 3e5 + 5;
const int maxm = 305;
ll arr[maxn];
ll arr1[maxn];
const ll mod = 1e9 + 7;
vector<ll> edges[maxn];
ll n, m, k, q, D, H, a, b, c, h, d, x, y, z, t;
string s, s1, s2;
ll gcd(ll a, ll b)
{
	ll t;
	while (b)
	{
		t = a;
		a = b;
		b = t % b;
	}
	return a;
}
ll par[maxn];
void init() {
	for (int i = 0; i < maxn; i++)
		par[i] = i;
}
void init(int n) {
	for (int i = 0; i < n+10; i++)
		par[i] = i;
}
ll find(int i) {
	if (par[i] != i) {
		return par[i] = find(par[i]);
	}
	else
		return i;
}
void merge(int x, int y) {
	par[find(x)] = par[find(y)];
}
ll presum[100];
bool isVowel(char c) {
	if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
		return true;
	else
		return false;
};

vector<int> get_pi(const string s) {
	int n = s.length();
	vector<int> pi(n);
	int k = 0;
	for (int i = 1; i < n; i++) {
		while (k > 0 && s[i] != s[k])
			k = pi[k - 1];
		if (s[i] == s[k])
			k++;
		pi[i] = k;
	}
	return pi;
}

int main() {
	cin >> t;
	while (t--) {
		cin >> n;
		vector<string> v;
		int one = 0;
		int zero = 0;
		vector<int> even;
		vector<int> odd;
		for (int i = 0; i < n; i++) {
			cin >> s;
			if (s.length() & 1) {
				odd.push_back(s.length());
			}
			else {
				even.push_back(s.length());
			}
			for (auto x : s) {
				if (x == '0')
					zero++;
				else
					one++;
			}
		}
		sort(odd.begin(), odd.end());
		sort(even.begin(), even.end());
		int ans = 0;
		for (auto x : even) {
			for (int i = 0; i <= one; i += 2) {
				if (zero >= x - i) {
					one -= i;
					zero -= (x - i);
					ans++;
					break;
				}
			}
		}
		for (auto x : odd) {
			bool ok = false;
			for (int i = 1; i <= one; i += 2) {
				if (zero >= (x - i)) {
					one -= i;
					zero -= (x - i);
					ans++;
					ok = true;
					break;
				}
			}
			if (!ok) {
				for (int i = 1; i <= zero; i += 2) {
					if (one >= (x - i)) {
						zero -= i;
						one -= (x - i);
						ans++;
						ok = true;
						break;
					}
				}
			}
		}
		cout << ans << endl;

	}
}


#include <iostream>
#include <string>

int main() {
    int q;
    std::cin >> q;

    for (std::string str; q--;) {
        int n;
        std::cin >> n;
        int swap_amt = 0;
        for (int i = 0; i < n; ++i) {
            std::cin >> str;
            if (str.size() % 2)
                swap_amt += str.size();
            else {
                int one_amt = 0;
                for (auto j : str)
                    one_amt += (j == '1');
                if (one_amt % 2)
                    --swap_amt;
            }
        }
        std::cout << (swap_amt >= 0 ? n : n - 1) << '\n';
    }

    return 0;
}


#include <iostream>
#include <string>

int main() {
    int q;
    std::cin >> q;

    for (std::string str; q--; std::cout << '\n') {
        bool odd_exist = false;
        bool broken_even = false;
        int n;
        std::cin >> n;
        for (int i = 0; i < n; ++i) {
            std::cin >> str;
            if (str.size() % 2)
                odd_exist = true;
            else {
                int one_amt = 0;
                for (auto j : str)
                    one_amt += (j == '1');
                if (one_amt % 2)
                    broken_even = !broken_even;
            }
        }
        if (odd_exist || !broken_even)
            std::cout << n;
        else std::cout << n - 1;
    }

    return 0;
}


#include <iostream>
#include <string>

int main() {
    int q;
    std::cin >> q;

    for (std::string str; q--;) {
        int n;
        std::cin >> n;
        int swap_amt = 0;
        for (int i = 0; i < n; ++i) {
            std::cin >> str;
            if (str.size() % 2)
                swap_amt += str.size();
            else {
                int one_amt = 0;
                for (auto j : str)
                    one_amt += (j == '1');
                if (one_amt % 2)
                    --swap_amt;
            }
        }
        std::cout << (swap_amt >= 0 ? n : n - 1);
    }

    return 0;
}


#include <iostream>
#include <string>

int main() {
    int q;
    std::cin >> q;

    for (std::string str; q--;) {
        bool odd_exist = false;
        bool broken_even = false;
        int n;
        std::cin >> n;
        for (int i = 0; i < n; ++i) {
            std::cin >> str;
            if (str.size() % 2)
                odd_exist = true;
            else {
                int one_amt = 0;
                for (auto j : str)
                    one_amt += (j == '1');
                if (one_amt % 2)
                    broken_even = !broken_even;
            }
        }
        if (odd_exist || !broken_even)
            std::cout << n << '\n';
        else std::cout << n - 1;
    }

    return 0;
}


#include <iostream>
#include <string>

int main() {
    int q;
    std::cin >> q;

    bool odd_exist = false;
    bool broken_even = false;
    for (std::string str; q--;) {
        int n;
        std::cin >> n;
        for (int i = 0; i < n; ++i) {
            std::cin >> str;
            if (str.size() % 2)
                odd_exist = true;
            else {
                int one_amt = 0;
                for (auto j : str)
                    one_amt += (j == '1');
                if (one_amt % 2)
                    broken_even = !broken_even;
            }
        }
        if (odd_exist || !broken_even)
            std::cout << n << '\n';
        else std::cout << n - 1;
    }

    return 0;
}


#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<cmath>
#define inf 1000000000000000000
#define MAX 1000010
#define mod 998244353
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main(){
	int t;
	int n;
	int aa;
	int bb;
	int a, b;
	cin >> t;
	while(t--){
		a = 0;
		b = 0;
		aa = 0;
		cin >>n;
		string s;
		int l = 0;
		for(int i = 1; i <= n; i++){
			cin >> s;
			int nn = s.length();
			if(nn % 2){
				aa++;
			}
			for(int j = 0; j < s.length(); j++){
				if(s[j] == '0'){
					a++;
					a %= 2;
				}
				else{
					b++;
					b %= 2;
				}
			}
		}
		int ans;
		if(aa >= (a + b) && (aa - a- b) % 2 == 0){
			ans = n;
		}
		else{
			ans = n - 1;
		}
		cout << ans << endl;
	}
	return 0;
}
/*
-----------------
|     /   \     |
|    /     \	|
|	/	    \   |
|    -------    |
|   |	    |	|
|	|       |   |
-----------------
*/


#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<cmath>
#define inf 1000000000000000000
#define MAX 1000010
#define mod 998244353
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main(){
	int t;
	int n;
	int aa;
	int bb;
	int a, b;
	cin >> t;
	while(t--){
		a = 0;
		b = 0;
		aa = 0;
		cin >>n;
		string s;
		int l = 0;
		for(int i = 1; i <= n; i++){
			cin >> s;
			int nn = s.length();
			if(nn % 2){
				aa++;
				aa%= 2;
			}
			for(int j = 0; j < s.length(); j++){
				if(s[j] == '0'){
					a++;
					a %= 2;
				}
				else{
					b++;
					b %= 2;
				}
			}
		}
		int ans;
		if(a + b == aa){
			ans = n;
		}
		else{
			ans = n - 1;
		}
		cout << ans << endl;
	}
	return 0;
}
/*
-----------------
|     /   \     |
|    /     \	|
|	/	    \   |
|    -------    |
|   |	    |	|
|	|       |   |
-----------------
*/


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> s(n);
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		string b;
		int q1 = 0;
		bool z = false;
		for (int j = 0; j < a; j++) {
			cin >> b;
			if (b.size() % 2 == 1) {
				z = true;
			}
			for (int k = 0; k < b.size(); k++) {
				if (b[k] == '1') {
					q1++;
				}
			}
		}
		if (z) {
			s[i] = a;
		}
		else {
			if (q1 % 2 == 0) {
				s[i] = a;
			}
			else {
				s[i] = a - 1;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << s[i] << '\n';
	}
 }


//~24.10.2019
#include<iostream>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<string>
#include<stack>
#include <cassert>
#include<algorithm>
#include<set>
#include <queue>
#include<map>
#include<numeric>
#include<climits>
using namespace std;

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define forn3(j, i, n) for(int j = int(i); j < int(n); j++)
#define all(vec) vec.begin(), vec.end()
//#define MAXI 2*000*000*000
//#define MAXL 9LL*1000*1000*1000*1000*1000*1000

using ll = long long;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vpii = vector<pair<int, int>>;

int up_bound_int = (1 << 31) - 1; //1+2*((1 << 30) - 1);
ll inf = 1e18, inf_prec = (1ll << 63) -1;

ll binpow(ll a, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1)
			res = (res * a) % 1000000007;
		a = (a * a) % 1000000007;
		n >>= 1;
	}
	return res;
}

const double PI = acos(-1);

int main() {
	int n,q;
	cin >> q;
	string s;
	forn(i, q) {
		cin >> n;
		int zeros=0, ones=0, odd=0;
		forn(j, n) {
			cin >> s;
			if (s.length() & 1)
				odd++;
			forn(k, s.length()) {
				if (s[k] == '0')
					zeros++;
				else
					ones++;
			}
		}
		if (zeros % 2 + ones % 2 <= odd)
			cout << n << endl;
		else
			cout << n - 1 << endl;
	}

	return 0;
}


//~24.10.2019
#include<iostream>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<string>
#include<stack>
#include <cassert>
#include<algorithm>
#include<set>
#include <queue>
#include<map>
#include<numeric>
#include<climits>
using namespace std;

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define forn3(j, i, n) for(int j = int(i); j < int(n); j++)
#define all(vec) vec.begin(), vec.end()
//#define MAXI 2*000*000*000
//#define MAXL 9LL*1000*1000*1000*1000*1000*1000

using ll = long long;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vpii = vector<pair<int, int>>;

int up_bound_int = (1 << 31) - 1; //1+2*((1 << 30) - 1);
ll inf = 1e18, inf_prec = (1ll << 63) -1;

ll binpow(ll a, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1)
			res = (res * a) % 1000000007;
		a = (a * a) % 1000000007;
		n >>= 1;
	}
	return res;
}

const double PI = acos(-1);

int main() {
	int n,q;
	cin >> q;
	string s;
	forn(i, q) {
		cin >> n;
		vector<int> a(n);
		int rand0 = 0, rand1 = 0, count1 = 0, count0 = 0;
		forn(k, n) {
			cin >> s;
			int tt = s.length(), count = 0;
			for (int j = 0; j < tt / 2; j++) {
				if (s[j] != s[tt - j - 1]) {
					count++;
				}
				else if (s[j] == '1')
					count1++;
				else
					count0++;
			}
			if (s.length() & 1) {
				if (s[tt / 2 + 1] == '1')
					rand1++;
				else
					rand0++;
			}
			a[k] = count;
		}
		sort(a.begin(), a.end());
		int ans = 0;
		forn3(k,0, n-1) {
			if (a[k] == 0)
				ans++;
			else if (a[k] == a[k + 1]) {
				ans++;
				a[k + 1] = 0;
			}
			else {
				ans++;
				a[k + 1] -= a[k];
			}
		}
		if (a[n - 1] == 0 || a[n - 1] <= max(rand1, rand0))
			ans++;
		else if (rand1 > 0 && rand1 + count1 * 2 <= a[n - 1]) {
			ans++;
		}
		else if (rand0 > 0 && rand0 + count0 * 2 <= a[n - 1])
			ans++;
		cout << ans << endl;
	}

	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
int main()
{
    int t;
    cin >> t;
    string s;
    while(t > 0){
        t--;
        int n;
        cin >> n;
        int cntz = 0, cnto = 0, cnt = 0;
        for(int j = 0; j < n; j++)
        {
            cin >> s;
            if(s.size() % 2 == 1)
                cnt++;
            for(int i = 0; i < s.size(); i++)
            {
                if(s[i] == '0')
                    cntz++;
                else
                    cnto++;
            }
        }
        if(cntz % 2 == 1 || cnto % 2 == 1)
        {
            cntz = 0;
            cnto = 1;
        }
        cout << n - max(0, cntz + cnto - cnt) << endl;
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
int main()
{
    int t;
    cin >> t;
    string s;
    while(t > 0){
        cin >> s;
        int cntz = 0, cnto = 0, cnt = 0;
        if(s.size() % 2 == 1)
            cnt++;
        for(int i = 0; i < s.size(); i++)
        {
            if(s[i] == '0')
                cntz++;
            else
                cnto++;
        }
        if(cntz % 2 == 1 || cnto % 2 == 0)
        {
            cntz = 0;
            cnto = 1;
        }
        cout << s.size() - max(0, cntz % 2 + cnto % 2 - cnt) << endl;
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
int main()
{
    int t;
    cin >> t;
    string s;
    while(t > 0){
        t--;
        cin >> s;
        int cntz = 0, cnto = 0, cnt = 0;
        if(s.size() % 2 == 1)
            cnt++;
        for(int i = 0; i < s.size(); i++)
        {
            if(s[i] == '0')
                cntz++;
            else
                cnto++;
        }
        if(cntz % 2 == 1 || cnto % 2 == 0)
        {
            cntz = 0;
            cnto = 1;
        }
        cout << s.size() - max(0, cntz % 2 + cnto % 2 - cnt) << endl;
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
int main()
{
    int t;
    cin >> t;
    string s;
    while(t > 0){
        cin >> s;
        int cntz = 0, cnto = 0, cnt = 0;
        if(s.size() % 2 == 1)
            cnt++;
        for(int i = 0; i < s.size(); i++)
        {
            if(s[i] == '0')
                cntz++;
            else
                cnto++;
        }
        if(cntz % 2 == 1 || cnto % 2 == 0)
        {
            cntz = 0;
            cnto = 1
        }
        cout << s.size() - max(0, cntz % 2 + cnto % 2 - cnt) << endl;
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
int main()
{
    int t;
    cin >> t;
    string s;
    while(t > 0){
        t--;
        int n;
        cin >> n;
        int cntz = 0, cnto = 0, cnt = 0;
        for(int j = 0; j < n; j++)
        {
            cin >> s;
            if(s.size() % 2 == 1)
                cnt++;
            for(int i = 0; i < s.size(); i++)
            {
                if(s[i] == '0')
                    cntz++;
                else
                    cnto++;
            }
        }
        if(cntz % 2 == 1 || cnto % 2 == 0)
        {
            cntz = 0;
            cnto = 1;
        }
        cout << n - max(0, cntz % 2 + cnto % 2 - cnt) << endl;
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
int main()
{
    int t;
    cin >> t;
    string s;
    while(t > 0){
        t--;
        int n;
        cin >> n;
        int cntz = 0, cnto = 0, cnt = 0;
        for(int j = 0; j < n; j++)
        {
            cin >> s;
            if(s.size() % 2 == 1)
                cnt++;
            for(int i = 0; i < s.size(); i++)
            {
                if(s[i] == '0')
                    cntz++;
                else
                    cnto++;
            }
        }
        if(cntz % 2 == 1 || cnto % 2 == 1)
        {
            cntz = 0;
            cnto = 1;
        }
        cout << n - max(0, cntz % 2 + cnto % 2 - cnt) << endl;
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
int main()
{
    int t;
    cin >> t;
    string s;
    while(t > 0){
        t--;
        int n;
        cin >> n;
        int cntz = 0, cnto = 0, cnt = 0;
        for(int j = 0; j < n; j++)
        {
            cin >> s;
            if(s.size() % 2 == 1)
                cnt++;
            for(int i = 0; i < s.size(); i++)
            {
                if(s[i] == '0')
                    cntz++;
                else
                    cnto++;
            }
        }
        if(cntz % 2 == 1 || cnto % 2 == 0)
        {
            cntz = 0;
            cnto = 1;
        }
        cout << s.size() - max(0, cntz % 2 + cnto % 2 - cnt) << endl;
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <iterator>
#include <cmath>

using namespace std;

int main()
{
	if (fopen("input.txt", "r")) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cout.tie(NULL);
    int q;
    cin >> q;
    while (q--) {
        int n;
        cin >> n;
        int k = 0, k1 = 0, k0 = 0;
        for (int i = 0; i != n; ++i) {
            string s;
            cin >> s;
            if (s.size() % 2)
                ++k;
            for (auto c : s)
                if (c == '1')
                    ++k1;
                else
                    ++k0;
        }
        if (k % 2 == 0)
            if (k0 % 2 != 0 || k1 % 2 != 0)
                cout << n - 1;
            else
                cout << n;
        else if ((k0 + k1) % 2 == 1)
            cout << n;
        else
            cout << n - 1;
        cout << '\n';
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <iterator>
#include <cmath>

using namespace std;

int main()
{
	if (fopen("input.txt", "r")) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cout.tie(NULL);
    int q;
    cin >> q;
    while (q--) {
        int n;
        cin >> n;
        int k = 0, k1 = 0, k0 = 0;
        for (int i = 0; i != n; ++i) {
            string s;
            cin >> s;
            if (s.size() % 2)
                ++k;
            for (auto c : s)
                if (c == '1')
                    ++k1;
                else
                    ++k0;
        }
        while (k > 0) {
            if (k0 % 2)
                --k0;
            else if (k1 % 2)
                --k1;
            else
                --k0;
            --k;
        }
        if (k0 % 2 || k1 % 2)
            cout << n - 1;
        else
            cout << n;
        cout << '\n';
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
using namespace std;

int main(){
//    freopen("input.txt", "rt", stdin);
  //  freopen("output.txt", "wt", stdout);
    int n, m, a[51], zero = 0, one = 0, k = 0, len = 0;
    string p;
    cin >> m;
    for (int i = 0; i < m; i++) {
        cin >> n;
        for (int j = 0; j < n; j++) {
            cin >> p;
            a[j] = p.length();
            len ++;
            for (int f = 0; f < a[j]; f++) {
                if (p[f] == '0') {
                    zero++;
                } else {
                    one++;
                }
            }
        }
        if (zero % 2 == 1) {
            k++;
        }
        if (one % 2 == 1) {
            k++;
        }
        for ( int j = 0; j < len; j++) {
            if (k == 0) {
                break;
            }
            if (a[j] % 2 == 1) {
                k--;
                a[j]--;
            }
        }
        if (k == 1) {
            if (zero % 2 == 1){
                zero = zero / 2 * 2;
            } else {
                one = one / 2 * 2;
            }
        }
        if (k == 0) {
            one = one / 2 * 2;
            zero = zero / 2 * 2;
        }
        if (zero % 2 == 0 && one % 2 == 0) {
            cout << n << endl;
        } else {
            cout << n-1 << endl;
        }
        one = 0;
        zero = 0;
        k = 0;
        len = 0;
    }
}


#include <stdio.h>
#include <vector>
#include <stack>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <ctime>

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int k = 0; k < n; k++)
#define FORN(k, s, n) for (int k = s; k < n; k++)
#define debug(x) printf("%s = %d\n", #x, x)
#define debug2(x, y) printf("%s = %d, %s = %d\n", #x, x, #y, y)
#define debug3(x, y, z) printf("%s = %d, %s = %d, %s = %d\n", #x, x, #y, y, #z, z)
#define debug4(x, y, z, t) printf("%s = %d, %s = %d, %s = %d, %s = %d\n", #x, x, #y, y, #z, z, #t, t)

#pragma warning(disable : 6031)
#pragma warning(disable : 4101)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef complex<double> cd;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);

// Solution

const int MAXN = 55;

int q, n, zs, os, A[MAXN];
char S[MAXN][MAXN];
bool flag;

int main() {
    scanf("%d", &q);

    while (q--) {
        scanf("%d", &n);
        zs = os = 0;
        flag = false;

        for (int i = 0; i < n; i++) {
            scanf(" %s", S[i]);
            A[i] = strlen(S[i]);

            if (A[i] % 2 == 1) {
                flag = true;
            }

            for (int k = 0; k < A[i]; k++) {
                if (S[i][k] == '0') {
                    zs++;
                } else {
                    os++;
                }
            }
        }

        if (!flag && (os % 2 == 1)) {
            printf("%d\n", n - 1);
        } else {
            printf("%d\n", n);
        }
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
#include<string>
#include<string.h>
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<functional>
#include<utility>
#include<iomanip>
#include<time.h>
#include<queue>
#include<map>
#include<limits.h>
#include<list>
#include<stack>
using namespace std;

//fast types
#define vi vector<int>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double dd;

/*primes in range 1 - n
1 - 100(1e2) -> 25 primes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293
*/

//defines
#define all(c)     c.begin(), c.end()
#define sz(c)      int(c.size())
#define read(f)    freopen(f, "r", stdin)
#define write(f)   freopen(f, "w", stdout)
#define rus      setlocale(LC_ALL, "Russian")
#define fast  std :: ios :: sync_with_stdio ( false )
#define am &
#define sc scanf
#define scd(a) scanf("%d",am a)
#define scdd(a,b) scanf("%d%d",am a,am b)
#define pr printf
#define mp make_pair
#define poo(i,a,b) for(ll i=a;i<=b;i++)
#define oop(i,a,b) for(ll i=a;i>=b;i--)

//constants
#define pi 3.141592653589793238462643383279
#define rad 57.295779513082320876798154814105170332405

namespace Help
{
	int mod = 1;
	int safe_mul(int a, int b)
	{
		return a * (ll)b % mod;
	}
	int safe_exp(int a, int b)
	{
		int rez = 1;
		for (; b > 0; b >>= 1)
		{
			if (b & 1)
				rez = safe_mul(rez, a);
			a = safe_mul(a,a);
		}
		return rez;
	}
	ll to_int(string a)
	{
		if (a.length() > 18)return 0;
		ll g=0,l=1;
		reverse(a.begin(), a.end());
		for (int i = 0; i < a.length(); i++)
		{
			g += (a[i] - '0') * l;
			l *= 10;
		}
		return g;
	}
	vector<string> split(string s,char c)
	{
		vector<string> ss;
		ss.push_back("");
		int last=0,ptr=0,k=0;
		for (int i = 0; i < s.length(); i++)
		{
			if (s[i] == c)
			{
				last = i;
				break;
			}
			ss[0] += s[i];
		}
		if (ss[0].length() != s.length())
		{
			ptr = last;
			ptr++;
			while (ptr < s.length())
			{
				k++;
				ss.push_back("");
				while (ptr != s.length())
				{
					if (s[ptr] == c)
					{
						ptr++;
						break;
					}
					ss[k].push_back(s[ptr]);
					ptr++;
				}
			}
		}
		return ss;
	}
	long long gcd(long long a, long long b)
	{
		while (a != 0 && b != 0)
		{
			if (a > b)
				a %= b;
			else
				b %= a;
		}
		return a + b;
	}
	void Qsort(int a[], int f, int q)
	{
		int l = f, r = q, x = a[(f + q) / 2];

		if (f >= q) return;
		while (l <= r)
		{
			while (a[l] > x)
				l++;
			while (a[r] < x)
				r--;
			if (l <= r)
			{
				swap(a[l], a[r]);
				l++;
				r--;
			}

		}
		Qsort(a, f, r);
		Qsort(a, l, q);
	}
	void Qsort(long long  a[], int f, int q)
	{
		long long l = f, r = q, x = a[(f + q) / 2], c;

		if (f >= q) return;
		while (l <= r)
		{
			while (a[l] < x)
				l++;
			while (a[r] > x)
				r--;
			if (l <= r)
			{
				swap(a[l], a[r]);
				l++;
				r--;
			}

		}
		Qsort(a, f, r);
		Qsort(a, l, q);
	}
	int binsearch(int n, int a[], int h)
	{
		int l = 0, r = h, c = n;
		while (l < r - 1)
		{
			c = (l + r) / 2;
			if (n < a[c])
				r = c;
			else l = c;
		}
		if (a[l] == n)
			return l + 1;
		else return -1;
	}
	bool isPrime(long long a)
	{
		long long i;
		if (a % 2 == 0)
			return 0;
		else
			for (i = 3; i * i <= a; i += 2)
				if (a % i == 0)
					return 0;
		return 1;
	}
	void reverse(long long a[], int l, int r)
	{
		long long tmp;
		for (int i = 0; i < (l - r + 1) / 2; i++)
		{
			tmp = a[l + i];
			a[l + i] = a[r-i];
			a[r - i] = tmp;
		}

	}
	void reverse(int a[], int l, int r)
	{
		int tmp;
		for (int i = 0; i < (r - l + 1) / 2; i++)
		{
			tmp = a[l + i];
			a[l + i] = a[r - i];
			a[r - i] = tmp;
		}

	}
};
int main()
{

	int q;
	scd(q);
	for (int j = 0; j < q; j++)
	{
		int n,slen=0, s0=0, s1=0;
		string s;
		scd(n);
		for (int i = 0; i < n; i++)
		{
			cin >> s;
			for (int l = 0; l < s.length(); l++)
				if (s[l] == '0')s0++;
				else s1++;
			slen += s.length();
		}
		if (slen % 2 == 1)printf("%d\n", n);
		else if (s0 % 2 == 0)printf("%d\n", n);
		else printf("%d\n", n - 1);
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
#include<string>
#include<string.h>
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<functional>
#include<utility>
#include<iomanip>
#include<time.h>
#include<queue>
#include<map>
#include<limits.h>
#include<list>
#include<stack>
using namespace std;

//fast types
#define vi vector<int>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double dd;

/*primes in range 1 - n
1 - 100(1e2) -> 25 primes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293
*/

//defines
#define all(c)     c.begin(), c.end()
#define sz(c)      int(c.size())
#define read(f)    freopen(f, "r", stdin)
#define write(f)   freopen(f, "w", stdout)
#define rus      setlocale(LC_ALL, "Russian")
#define fast  std :: ios :: sync_with_stdio ( false )
#define am &
#define sc scanf
#define scd(a) scanf("%d",am a)
#define scdd(a,b) scanf("%d%d",am a,am b)
#define pr printf
#define mp make_pair
#define poo(i,a,b) for(ll i=a;i<=b;i++)
#define oop(i,a,b) for(ll i=a;i>=b;i--)

//constants
#define pi 3.141592653589793238462643383279
#define rad 57.295779513082320876798154814105170332405

namespace Help
{
	int mod = 1;
	int safe_mul(int a, int b)
	{
		return a * (ll)b % mod;
	}
	int safe_exp(int a, int b)
	{
		int rez = 1;
		for (; b > 0; b >>= 1)
		{
			if (b & 1)
				rez = safe_mul(rez, a);
			a = safe_mul(a,a);
		}
		return rez;
	}
	ll to_int(string a)
	{
		if (a.length() > 18)return 0;
		ll g=0,l=1;
		reverse(a.begin(), a.end());
		for (int i = 0; i < a.length(); i++)
		{
			g += (a[i] - '0') * l;
			l *= 10;
		}
		return g;
	}
	vector<string> split(string s,char c)
	{
		vector<string> ss;
		ss.push_back("");
		int last=0,ptr=0,k=0;
		for (int i = 0; i < s.length(); i++)
		{
			if (s[i] == c)
			{
				last = i;
				break;
			}
			ss[0] += s[i];
		}
		if (ss[0].length() != s.length())
		{
			ptr = last;
			ptr++;
			while (ptr < s.length())
			{
				k++;
				ss.push_back("");
				while (ptr != s.length())
				{
					if (s[ptr] == c)
					{
						ptr++;
						break;
					}
					ss[k].push_back(s[ptr]);
					ptr++;
				}
			}
		}
		return ss;
	}
	long long gcd(long long a, long long b)
	{
		while (a != 0 && b != 0)
		{
			if (a > b)
				a %= b;
			else
				b %= a;
		}
		return a + b;
	}
	void Qsort(int a[], int f, int q)
	{
		int l = f, r = q, x = a[(f + q) / 2];

		if (f >= q) return;
		while (l <= r)
		{
			while (a[l] > x)
				l++;
			while (a[r] < x)
				r--;
			if (l <= r)
			{
				swap(a[l], a[r]);
				l++;
				r--;
			}

		}
		Qsort(a, f, r);
		Qsort(a, l, q);
	}
	void Qsort(long long  a[], int f, int q)
	{
		long long l = f, r = q, x = a[(f + q) / 2], c;

		if (f >= q) return;
		while (l <= r)
		{
			while (a[l] < x)
				l++;
			while (a[r] > x)
				r--;
			if (l <= r)
			{
				swap(a[l], a[r]);
				l++;
				r--;
			}

		}
		Qsort(a, f, r);
		Qsort(a, l, q);
	}
	int binsearch(int n, int a[], int h)
	{
		int l = 0, r = h, c = n;
		while (l < r - 1)
		{
			c = (l + r) / 2;
			if (n < a[c])
				r = c;
			else l = c;
		}
		if (a[l] == n)
			return l + 1;
		else return -1;
	}
	bool isPrime(long long a)
	{
		long long i;
		if (a % 2 == 0)
			return 0;
		else
			for (i = 3; i * i <= a; i += 2)
				if (a % i == 0)
					return 0;
		return 1;
	}
	void reverse(long long a[], int l, int r)
	{
		long long tmp;
		for (int i = 0; i < (l - r + 1) / 2; i++)
		{
			tmp = a[l + i];
			a[l + i] = a[r-i];
			a[r - i] = tmp;
		}

	}
	void reverse(int a[], int l, int r)
	{
		int tmp;
		for (int i = 0; i < (r - l + 1) / 2; i++)
		{
			tmp = a[l + i];
			a[l + i] = a[r - i];
			a[r - i] = tmp;
		}

	}
};
int main()
{

	int q;
	scd(q);
	for (int j = 0; j < q; j++)
	{
		int n,slen=0, s0=0, s1=0;
		bool nech = false;
		string s;
		scd(n);
		for (int i = 0; i < n; i++)
		{
			cin >> s;
			for (int l = 0; l < s.length(); l++)
				if (s[l] == '0')s0++;
				else s1++;
			slen += s.length();
			if (s.length() % 2 == 1)nech = true;
		}
		if (slen % 2 == 1)printf("%d\n", n);
		else if (s0 % 2 == 0||nech)printf("%d\n", n);
		else printf("%d\n", n - 1);
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <queue>
using namespace std;
int n;
int a[100];
int main() {
	int T;
	cin >> T;
	while (T--)
	{
		string t;
		int Ans = 0;
		int n0 = 0;
		int n1 = 0;
		int m0 = 0;
		int m1 = 0;
		cin >> n;
		for (int i = 1; i <= n; ++i)
		{
			cin >> t;
			a[i] = t.size();
			if (a[i] % 2 == 0) m0++;
			else m1++;
			for (auto c : t)
			{
				if (c == '0') n0++;
				else n1++;
			}
		}
		if (n0 % 2 == 1) m1--;
		if (n1 % 2 == 1) m1--;
		if (m1 < 0) Ans = n-1; else Ans = n;
		cout << Ans << "\n";
	}
	return 0;
}


#include <iostream>
#include <string>
#include <ctime>
#include <vector>
using namespace std;

/*
ifstream cin("input.txt");
ofstream cout("output.txt");
*/
int main() {
	int t;
	cin >> t;
	for(int q = 0; q<t; ++q)
	{
		int n, w = 0, sum = 0;
		cin >> n;
		vector <string> s(n);
		for (int i = 0; i < n; ++i)
		{
			cin >> s[i];
			string str = s[i];
			if (str.size() % 2 == 1) w = 1;
		}
		for (int i = 0; i < n; ++i)
		{
			string str = s[i];
			for (int j = 0; j < str.size(); ++j)
			{
				sum += s[i][j];
				sum %= 2;
			}
		}
		if (w == 1 || sum == 0) cout << n << endl;
		else cout << n - 1 << endl;
	}
}


#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>

using namespace std;

int main()
{
	int tc, cases;
	int n;
	vector<int> len;
	string str;
	char input[1000];
	int i, j;
	int cnt[2];
	char cur;
	int parity[2];
	int k;
	int sol;

	scanf("%d", &cases);

	for (tc = 0; tc < cases; tc++)
	{
		scanf("%d", &n);

		len.clear();

		k = 0;
		sol = 0;

		cnt[0] = cnt[1] = 0;

		for (i = 0; i < n; i++)
		{
			scanf("%s", input);

			str = input;

			for (j = 0; j < str.size(); j++)
			{
				cnt[str[j] - '0']++;
			}

			len.push_back(str.size());

			if (str.size() % 2)
			{
				k++;
			}

			else
			{
				sol++;
			}
		}

		parity[0] = cnt[0] % 2;
		parity[1] = cnt[1] % 2;

		if ((parity[0] + parity[1]) % 2 == k % 2 && ((!parity[0] || !parity[1]) || k))
		{
			sol += k;
		}

		else
		{
			sol += k - 1;
		}

		printf("%d\n", sol);
	}

	return 0;
}


#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main(){

    int t;
    cin>>t;

    while(t--){

        int n;
        cin>>n;

        vector<string> v(n);
        int c=0;
        for(int i=0;i<n;i++){
            cin>>v[i];
            if(v[i].size()%2==1)
                c=1;
        }

        if(c==1){
            cout<<n<<"\n";
            continue;
        }
        int od=0,ev=0;
        for(int i=0;i<n;i++){
            int o=0,z=0;
            for(int j=0;j<v[i].size();j++){
                if(v[i][j]=='1')
                    o++;
                else
                    z++;
            }
            if(o%2==1)
                od++;
            else
                ev++;

        }

        int res = ev;

        if(od%2==1)
            cout<<n-1<<"\n";
        else
            cout<<n<<"\n";

    }

    return 0;
}


#include <cstdio>
#include<iostream>
#include<string>

using namespace std;

int t,n,num0,k;
string s;

int main()
{
	cin >> t;
	while(t--)
	{
		cin >> n;
		num0 = k = 0;
		for(int i = 0; i < n; i++)
		{
			cin >> s;
			int len = s.size();
			for(int j = 0; j < len; j++)
			{
				if(s[j] == '0')
					num0++;
			}
			if(len%2 == 1)
				k++;
		}
		if(k == 0 && num0%2 ==  1)
			cout << n - 1 <<endl;
		else
			cout << n << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int t,n,num0,k;
string s;

int main()
{
	cin >> t;
	while(t--)
	{
		cin >> n;
		num0 = k = 0;
		for(int i = 0; i < n; i++)
		{
			cin >> s;
			int len = s.size();
			for(int j = 0; j < len; j++)
			{
				if(s[j] == '0')
					num0++;
			}
			if(len%2 == 1)
				k++;
		}
		if(k == 0 && num0%2 ==  1)
			cout << n - 1 <<endl;
		else
			cout << n << endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <cstring>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define fr(i, l, r) for(int i = l; i < r; ++i)
#define fr_sl(i, l, r) for(auto i = sl.begin(); i != sl.end(); ++i)
#define elif else if
#define mp make_pair
#define pb push_back

ll inf = 1000000007;
int n, v, m, v0, v1, gv1, gv0, p, h;
int mas[1000];
string s;
map<char, int> sl;
vector <int> vec;

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	scanf("%d", &m);
	fr(j, 0, m) {
		scanf("%d", &n);
		v0 = 0;
		v1 = 0;
		gv0 = 0;
		gv1 = 0;
		p = 0;
		h = 0;
		fr(l, 0, n) {
			cin >> s;
			v0 = 0;
			v1 = 0;
			fr(i, 0, s.size()) {
				if (s[i] == '0')
					++v0;
				else
					++v1;
			}
			if (v1 % 2 == 0 || v0 % 2 == 0) {
				if (s.size() % 2 == 1)
					++h;
			}
			else
				++p;
		}
		if (p % 2 == 0)
			printf("%d\n", n);
		else {
			if (h != 0)
				printf("%d\n", n);
			else
				printf("%d\n", n - 1);
		}
	}
	return 0;
}


#include<iostream>
#include<cstdlib>
#include<vector>
#include<string>

using namespace std;

typedef long long ll;

int main() {

	ll t;
	cin >> t;

	for (int k = 0; k < t; k++) {
		ll n, a[2] = {0, 0}, ns = 0;
		cin >> n;

		for (int i = 0; i < n; i++) {
			string s;
			cin >> s;

			if (s.length() % 2) ns++;

			for (char c : s)
				a[c - '0']++;
		}

		if (ns % 2) {
			if (a[0] % 2 != a[1] % 2) cout << n << endl;
			else cout << n - 1 << endl;
		}
		else {
			if (a[0] % 2 == 0 && a[1] % 2 == 0) cout << n << endl;
			else cout << n - 1 << endl;
		}
	}

	//system("pause");
	return 0;
}


#include<iostream>
#include<cstdlib>
#include<vector>
#include<string>

using namespace std;

typedef long long ll;

int main() {

	ll t;
	cin >> t;

	for (int k = 0; k < t; k++) {
		ll n, a[2] = { 0, 0 }, ns = 0;
		cin >> n;

		for (int i = 0; i < n; i++) {
			string s;
			cin >> s;

			if (s.length() % 2) ns++;

			for (char c : s)
				a[c - '0']++;
		}

		if (ns == 0 && a[0] % 2 && a[1] % 2) {
			cout << n - 1 << endl;
		}
		else cout << n << endl;
	}

	system("pause");
	return 0;
}


#include<iostream>
#include<cstdlib>
#include<vector>
#include<string>

using namespace std;

typedef long long ll;

int main() {

	ll t;
	cin >> t;

	for (int k = 0; k < t; k++) {
		ll n, a[2] = {0, 0}, ns = 0;
		cin >> n;

		for (int i = 0; i < n; i++) {
			string s;
			cin >> s;

			if (s.length() % 2) ns++;

			for (char c : s)
				a[c - '0']++;
		}

		if (ns == 0) {
			if (a[0] % 2 == 0 && a[1] % 2 == 0)cout << n << endl;
			else cout << n - 1 << endl;
			continue;
		}

		if (ns % 2) {
			if (a[0] % 2 != a[1] % 2) cout << n << endl;
			else cout << n - 1 << endl;
		}
		else {
			if (a[0] % 2 == 0 && a[1] % 2 == 0) cout << n << endl;
			else cout << n - 1 << endl;
		}
	}

	//system("pause");
	return 0;
}


#include<iostream>
#include<cstdlib>
#include<vector>
#include<string>

using namespace std;

typedef long long ll;

int main() {

	ll t;
	cin >> t;

	for (int k = 0; k < t; k++) {
		ll n, a[2] = { 0, 0 }, ns = 0;
		cin >> n;

		for (int i = 0; i < n; i++) {
			string s;
			cin >> s;

			if (s.length() % 2) ns++;

			for (char c : s)
				a[c - '0']++;
		}

		if (ns == 0 && a[0] % 2 && a[1] % 2) {
			cout << n - 1 << endl;
		}
		else cout << n << endl;
	}

	//system("pause");
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int N, T;
bool chk[30];

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> T;
	while(T--) {
		int sum = 0, cnt = 0;
		cin >> N;
		for(int i=1; i<=N; i++) {
			string s; cin >> s;
			if(s.size() % 2) cnt++;
			for(int j=0; j<s.size(); j++) if(s[j] == '1') sum++;
		}
		if(!cnt && (sum % 2 == 1)) cout << N - 1 << '\n';
		else cout << N << '\n';
	}
}


#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int q;
	cin>>q;
	while(q--){
		int n,i,j,h,x=0,y=0,ans=0,a=0,b=0;
		string s;
		cin>>n;
		for(i=0;i<n;i++){
			cin>>s;
			if(s.size()%2==1) a++;
			else b++;
			for(j=0;j<s.size();j++){
				if(s[j]=='1') x++;
				else y++;
			}
		}
		while(a!=0){
			if(x%2==1&&x!=0){
				x--;
			}
			else{
				y--;
			}
			a--;
		}
		if(x%2==0&&y%2==0){
			ans=n;
		}
		else{
			ans=n-1;
		}
		cout<<ans<<endl;
	}
}


#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int q;
	cin>>q;
	while(q--){
		int n,i,j,h,x=0,y=0,ans=0,a=0;
		string s;
		cin>>n;
		for(i=0;i<n;i++){
			cin>>s;
			a+=s.size();
			for(j=0;j<s.size();j++){
				if(s[j]=='1') x++;
				else y++;
			}
		}
		if(a%2==1){
			ans=n;
		}
		else if(x%2==0){
			ans=n;
		}
		else{
			ans=n-1;
		}
		cout<<ans<<endl;
	}
}


#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int q;
	cin>>q;
	while(q--){
		int n,i,j,h,x=0,y=0,ans=0,a=0;
		string s;
		cin>>n;
		for(i=0;i<n;i++){
			cin>>s;
			a+=s.size();
			for(j=0;j<s.size();j++){
				if(s[j]=='1') x++;
				else y++;
			}
		}
		if(a%2==1){
			if((x%2==1&&y%2==0)||(x%2==0&&y%2==1)){
				ans=n;
			}
			else{
				ans=n-1;
			}
		}
		else{
			if(x%2==y%2&&x%2==0){
				ans=n;
			}
			else{
				ans=n-1;
			}
		}
		cout<<ans<<endl;
	}
}


#include <iostream>
#include <string>
using namespace std;

int Q, n, c0;
string s;

int main()
{
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		cin >> n;
		c0 = 0;
		for (int j = 0; j < n; j++) {
			cin >> s;
			if (c0 == -2) continue;
			if (s.size() % 2 == 1) {
				c0 = -2;
				continue;
			}
			for (char c : s) {
				if (c == '0') {
					c0++;
				}
			}
		}
		//cout << "    ";
		if (c0 % 2 == 1) cout << n - 1 << endl;
		else cout << n << endl;
	}
	return 0;
}


// It`s                  (
// time                   )
// to                    (
// get            /\  .-"""-.  /\
// wrong         //\\/  ,,,  \//\\
// answer!       |/\| ,;;;;;, |/\|
//               //\\\;-"""-;///\\
//              //  \/   .   \/  \\
//             (| ,-_| \ | / |_-, |)
//               //`__\.-.-./__`\\
//              // /.-(() ())-.\ \\
//             (\ |)   '---'   (| /)
//              ` (| OMNOMNOM  |) `
//                \)           (/

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <iomanip> // setprecision(10)

//#define OUT

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ull> vull;

const long double PI = 3.1415926535897932384626433832;

int main() {
#ifdef OUT
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q;
	cin >> q;
	while (q--) {
		int n;
		int z = 0;
		int o = 0;
		cin >> n;
		int globsize = 0;
		bool test = 0;
		string s;
		for (int i = 0; i < n; i++) {
			cin >> s;
			globsize += s.length();
			if (globsize % 2 != 0) {
				test = 1;
			}
			for (int j = 0; j < s.length(); j++) {
				if (s[j] == '1') {
					o++;
				}
				else {
					z++;
				}
			}
		}
		if (z % 2 == 0 && o % 2 == 0) {
			cout << n << endl;
		}
		else {
			if (test == 1) {
				cout << n << endl;
			}
			else {
				cout << n - 1 << endl;
			}
		}
	}
	return 0;
}


#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <list>
#include <math.h>
#include <map>
#include <functional>
#include <string>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;

#define MOD 1000000007

void solve()
{
	int n;
	cin >> n;

	int even_bad = 0;
	int odd_cnt = 0;
	for (int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		if (s.size() % 2 == 1)
		{
			odd_cnt++;
		}
		else
		{
			int cnt[2] = { 0,0 };
			for (char c : s)
			{
				cnt[c - '0']++;
			}
			if (cnt[0] % 2 == 1)
				even_bad++;
		}
	}

	if (even_bad % 2 == 1 && odd_cnt == 0)
	{
		cout << n - 1 << "\n";
	}
	else
	{
		cout << n << "\n";
	}
}

int main()
{
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	cout.tie(NULL);

	int t;
	cin >> t;
	while (t-- > 0)
		solve();

	return 0;
}


#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<list>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<limits>
using namespace std;

#define au auto
#define debug(i) cout<<"<debug> "<<i<<"<\debug>"<<endl
#define mfor(i,a,b) for(register int i=(a);i<=(b);i++)
#define mrep(i,a,b) for(register int i=(a);i>=(b);i--)
#define LLL __int128
#define Re register
#define il inline
#define mem(a,b) memset(a,(b),sizeof(a))
typedef pair<int, int> intpair;
typedef long long int LL;
const int INF = 0x3f3f3f3f;
const long long int INFLL = 0x3f3f3f3f3f3f3f3f;

const int maxn = 100010;

int n;
int T;
string s;
int cnt;
int cntf;

int main()
{
	cin >> T;
	while (T--)
	{
		cnt = cntf = 0;
		cin >> n;
		mfor(i, 1, n)
		{
			cin >> s;
			if (s.length() % 2) cnt++;
			int cnt = 0;
			mfor(j, 0, (int)s.length() / 2 - 1)
			{
				if (s[i] != s[s.length() - i - 1]) cntf++;
			}
		}
		if (cntf && !cnt) cout << n - 1 << endl;
		else cout << n << endl;
	}
}


#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<list>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<limits>
using namespace std;

#define au auto
#define debug(i) cout<<"<debug> "<<i<<"<\debug>"<<endl
#define mfor(i,a,b) for(register int i=(a);i<=(b);i++)
#define mrep(i,a,b) for(register int i=(a);i>=(b);i--)
#define LLL __int128
#define Re register
#define il inline
#define mem(a,b) memset(a,(b),sizeof(a))
typedef pair<int, int> intpair;
typedef long long int LL;
const int INF = 0x3f3f3f3f;
const long long int INFLL = 0x3f3f3f3f3f3f3f3f;

const int maxn = 100010;

int n;
int T;
string s;
int cnt;
int cntf;

int main()
{
	cin >> T;
	while (T--)
	{
		cnt = cntf = 0;
		cin >> n;
		mfor(i, 1, n)
		{
			cin >> s;
			if (s.length() % 2) cnt++;
			int cnt = 0;
			mfor(j, 0, (int)s.length() / 2 - 1)
			{
				if (s[i] != s[s.length() - j - 1]) cntf++;
			}
		}
		if (cntf % 2 && !cnt) cout << n - 1 << endl;
		else cout << n << endl;
	}
}


#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<list>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<limits>
using namespace std;

#define au auto
#define debug(i) cout<<"<debug> "<<i<<"<\debug>"<<endl
#define mfor(i,a,b) for(register int i=(a);i<=(b);i++)
#define mrep(i,a,b) for(register int i=(a);i>=(b);i--)
#define LLL __int128
#define Re register
#define il inline
#define mem(a,b) memset(a,(b),sizeof(a))
typedef pair<int, int> intpair;
typedef long long int LL;
const int INF = 0x3f3f3f3f;
const long long int INFLL = 0x3f3f3f3f3f3f3f3f;

const int maxn = 100010;

int n;
int T;
string s;
int cnt;
int cntf;

int main()
{
	cin >> T;
	while (T--)
	{
		cnt = cntf = 0;
		cin >> n;
		mfor(i, 1, n)
		{
			cin >> s;
			if (s.length() % 2) cnt++;
			int cnt = 0;
			mfor(j, 0, (int)s.length() / 2 - 1)
			{
				if (s[i] != s[s.length() - i - 1]) cntf++;
			}
		}
		if (cntf % 2 && !cnt) cout << n - 1 << endl;
		else cout << n << endl;
	}
}


#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<list>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<limits>
using namespace std;

#define au auto
#define debug(i) cout<<"<debug> "<<i<<"<\debug>"<<endl
#define mfor(i,a,b) for(register int i=(a);i<=(b);i++)
#define mrep(i,a,b) for(register int i=(a);i>=(b);i--)
#define LLL __int128
#define Re register
#define il inline
#define mem(a,b) memset(a,(b),sizeof(a))
typedef pair<int, int> intpair;
typedef long long int LL;
const int INF = 0x3f3f3f3f;
const long long int INFLL = 0x3f3f3f3f3f3f3f3f;

const int maxn = 100010;

int n;
int T;
string s;
int cnt;
int cnte;
int cnti;
vector<int>need;

int main()
{
	cin >> T;
	bool f;
	bool fl = false;;
	while (T--)
	{
		f = true;
		fl = false;
		cin >> n;
		mfor(i, 1, n)
		{
			cin >> s;
			if (s.length() % 2) fl = true;
			int cnt = 0;
			mfor(j, 0, (int)s.length() / 2 - 1)
			{
				if (s[i] != s[s.length() - i - 1]) cnt++;
			}
			if (cnt && 1) f = false;
		}
		if (fl || f) cout << n << endl;
		else cout << n - 1;
	}
}


#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<list>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<limits>
using namespace std;

#define au auto
#define debug(i) cout<<"<debug> "<<i<<"<\debug>"<<endl
#define mfor(i,a,b) for(register int i=(a);i<=(b);i++)
#define mrep(i,a,b) for(register int i=(a);i>=(b);i--)
#define LLL __int128
#define Re register
#define il inline
#define mem(a,b) memset(a,(b),sizeof(a))
typedef pair<int, int> intpair;
typedef long long int LL;
const int INF = 0x3f3f3f3f;
const long long int INFLL = 0x3f3f3f3f3f3f3f3f;

const int maxn = 100010;

int n;
int T;
string s;
int cnt;
int cnte;
int cnti;
vector<int>need;

int main()
{
	cin >> T;
	bool f;
	bool fl = false;;
	while (T--)
	{
		f = true;
		fl = false;
		cin >> n;
		mfor(i, 1, n)
		{
			cin >> s;
			if (s.length() % 2) fl = true;
			int cnt = 0;
			mfor(j, 0, (int)s.length() / 2 - 1)
			{
				if (s[i] != s[s.length() - i - 1]) cnt++;
			}
			if (cnt & 1) f = false;
		}
		if (fl || f) cout << n << endl;
		else cout << n - 1 << endl;
	}
}


#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<list>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<limits>
using namespace std;

#define au auto
#define debug(i) cout<<"<debug> "<<i<<"<\debug>"<<endl
#define mfor(i,a,b) for(register int i=(a);i<=(b);i++)
#define mrep(i,a,b) for(register int i=(a);i>=(b);i--)
#define LLL __int128
#define Re register
#define il inline
#define mem(a,b) memset(a,(b),sizeof(a))
typedef pair<int, int> intpair;
typedef long long int LL;
const int INF = 0x3f3f3f3f;
const long long int INFLL = 0x3f3f3f3f3f3f3f3f;

const int maxn = 100010;

int n;
int T;
string s;
int cnt;
int cntf;

int main()
{
	cin >> T;
	while (T--)
	{
		cnt = cntf = 0;
		cin >> n;
		mfor(i, 1, n)
		{
			cin >> s;
			if (s.length() % 2) cnt++;
			int cnt = 0;
			mfor(j, 0, (int)s.length() / 2 - 1)
			{
				if (s[j] != s[s.length() - j - 1]) cntf++;
			}
		}
		if (cntf % 2 && !cnt) cout << n - 1 << endl;
		else cout << n << endl;
	}
}


#include <iostream>
// Author: MrLolthe1st
#include <map>
#include <set>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<long long, long long>
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<long long>
#define int long long
#define _ << " " <<
#define all(a) a.begin(), a.end()
#define srt(a) std::sort(a.begin(), a.end())
#define double long double
typedef string str;

template<typename T>
inline istream& operator >>(istream& in, vec<T>& a) {
	for (int i = 0; i < a.size(); i++) in >> a[i];
	return in;
}

template<typename T>
inline ostream& operator <<(ostream& out, vec<T>& a) {
	for (int i = 0; i < a.size(); i++) out << a[i] << " ";
	return out;
}

template<typename T, typename E>
inline istream& operator >>(istream& in, pair<T, E>& a) {
	in >> a.first >> a.second;
	return in;
}

template<typename T>
T gcd(T a, T b) {
	T c;
	while (b) {
		c = a % b;
		a = b;
		b = c;
	}
	return a;
}

template<typename T>
T lcm(T a, T b) {
	return (a / gcd(a, b)) * b;
}

#include <sstream>
#define sqr(a) (a)*(a)
#define X first
#define Y second

void solve()
{
	int t;
	cin >> t;
	while (t--) {
		int n;
		string s;
		cin >> n;
		int a[2] = {};
		vi l; bool f = false;
		for (int i = 0; i < n; i++) {
			cin >> s;
			if (!(s.length() % 2))
				for (int j = 0; j < s.length(); j++)
					a[s[j] - '0']++;
			else f = true;
		}
		if (f) cout << n;
		else {
			if (a[0] % 2) cout << n - 1;
			else cout << n;
		}
		cout << "\n";
	}
}

int32_t main() {
	ios::sync_with_stdio(false);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	solve();
	int k;
	cin >> k;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>

using namespace std;

void solve() {
	int n;
	cin >> n;
	int cnt0 = 0, cnt1 = 0, f0 = 0, f1 = 0;
	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		if (s.size() & 1)
			f1 = 1;
		else
			f0 = 1;
		for (int j = 0; j < s.size(); ++j) {
			cnt0 += (s[j] == '0');
			cnt1 += (s[j] == '1');
		}
	}

	if (((cnt0 & 1) || (cnt1 & 1)) && !f1)
		cout << n - 1 << endl;
	else
		cout << n << endl;
}

int main() {
	int t;
	cin >> t;
	for (int i = 0; i < t; ++i)
		solve();
	return 0;
}


#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<string>
#include<set>
#define ll long long
using namespace std;
char a[100100];
char b[100010];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        int sum=0,sum1=0,sum2=0;
        for(int i=0;i<n;i++)
        {
            scanf("%s",a);
            int m=strlen(a);
            if(m%2==1)
                sum++;
            for(int i=0;i<m;i++)
            {
                if(a[i]=='1')
                sum1++;
                else
                    sum2++;
            }
        }
        sum1=sum1%2;
        sum2=sum2%2;
        if(sum1+sum2>sum)
        {
            printf("%d\n",n-1);
        }
        else
        {
            int u=sum-(sum1+sum2);
            if(u%2==1)
            {
                printf("%d\n",n-1);
            }
            else
                printf("%d\n",n);
        }
    }
}


#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <utility>
#include <unordered_map>
#include <unordered_set>

using namespace std;

template<class T>
void getInput(std::vector<T> &v, int count)
{
	v.resize(count);
	for (int i = 0; i < count; i++)
	{
		cin >> v[i];
	}
}

namespace BinaryPalindrome
{
	int solve(const vector<string> &input)
	{
		int num_odd = 0;
		int num_zeroes = 0, num_ones = 0;
		for (const auto &binStr : input)
		{
			if (binStr.size() % 2 == 1)
				num_odd++;

			for (const auto &chr : binStr)
			{
				if (chr == '1')
					num_ones++;
				else
					num_zeroes++;
			}
		}

		for (const auto &binStr : input)
		{
			if (binStr.size() >= num_ones)
			{
				num_ones -= binStr.size();
			}
			else
			{
				num_zeroes = binStr.size() - num_ones;
				break;
			}
		}

		if ((num_ones + num_zeroes) % 2 == 0 &&
			(num_ones % 2 == 1 || num_zeroes % 2 == 1) &&
			num_odd == 0)
		{
			return input.size() - 1;
		}

		return input.size();
	}
};

int main()
{
	int q;
	cin >> q;

	vector<int> solution;
	for (size_t i = 0; i < q; i++)
	{
		int n;
		cin >> n;
		std::vector<string> binVecSet;
		binVecSet.reserve(n);
		for (size_t j = 0; j < n; j++)
		{
			string input;
			cin >> input;
			binVecSet.push_back(input);
		}

		solution.push_back(BinaryPalindrome::solve(binVecSet));
	}

	for (const auto &item : solution)
	{
		cout << item << endl;
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <string>
#include <string.h>
using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s;
		int k, khui = 0, knechet = 0;
		cin >> k;
		for (int j = 0; j < k; j++) {
			cin >> s;
			if (s.length() % 2 == 1)
				knechet++;
			else {
				int k0 = 0, k1 = 0;
				for (int l = 0; l < s.length(); l++) {
					if (s[l] == '0')
						k0++;
				}
				if (k0 % 2 == 1)
					khui++;
			}
		}
		if (khui % 2 == 1 && knechet == 0)
			cout << k - 1 << endl;
		else
			cout << k << endl;
	}

}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <string>
#include <string.h>
using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s;
		int k, k0 = 0, k1 = 0, kchet = 0;
		cin >> k;
		for (int j = 0; j < k; j++) {
			cin >> s;
			if (s.length() % 2 == 0)
				kchet++;
			for (int l = 0; l < s.length(); l++) {
				if (s[l] == '0')
					k0++;
				else
					k1++;
			}
		}
		if ((kchet % 2 == 1 || k == kchet) && k0 % 2 == 1 && k1 % 2 == 1)
			cout << k - 1 << endl;
		else
			cout << k << endl;
	}

}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <string>
#include <string.h>
using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s;
		int k, k0 = 0, k1 = 0, kchet = 0;
		cin >> k;
		for (int j = 0; j < k; j++) {
			cin >> s;
			if (s.length() % 2 == 0)
				kchet++;
			for (int l = 0; l < s.length(); l++) {
				if (s[l] == '0')
					k0++;
				else
					k1++;
			}
		}
		if (kchet % 2 == 1 && k0 % 2 == 1 && k1 % 2 == 1)
			cout << k - 1 << endl;
		else
			cout << k << endl;
	}
}


#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main(void) {
	int q, i, n, j, k;
	int len_odd, num_one;
	cin >> q;
	string str;
	for (i = 0; i < q; i++) {
		len_odd = 0, num_one = 0;
		cin >> n;
		for (j = 0; j < n; j++) {
			cin >> str;
			len_odd += (str.length()) & 1;
			for (k = 0; k < str.length(); k++) if (str[k] == '1') num_one++;
			num_one = (num_one & 1);
		}
		if (len_odd == 0 && num_one == 1) cout << n - 1 << endl;
		else cout << n << endl;
	}
	return 0;
}


#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#define _USE_MATH_DEFINES
#include <stdio.h>
#include <functional>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
#include <regex>
#include <queue>
#include <string>
#include <set>

typedef  long long lol;
using namespace std;

#define fori(i,j,k) for (int (i)=(j);(i) < (k);(i)++)
#define MOD 4294967296ULL
#define EPS 0.000000001

void solve()
{
	int n;
	cin >> n;

	int chetn = 0, nech = 0;
	int tot0 = 0, tot1 = 0;
	for (int i = 0; i < n; i++)
	{
		string x;
		cin >> x;
		for (char cc : x)
		{
			if (cc == '0')
				tot0++;
			else
				tot1 ++;
		}

		if (x.size() % 2 == 1)
			nech++;
		else
			chetn++;
	}

	for (int x = 0; x <= tot0; x++)
	{
		if (x > nech) continue;

		int newtot0 = tot0 - x;
		int newtot1 = tot1 - (nech - x);
		if (newtot1 < 0)
			continue;

		if (newtot0 % 2 == 0 && newtot1 % 2 == 0)
		{
			cout << n << "\n";
			return;
		}

	}

	cout << n - 1 << "\n";
}

int main() {

#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;

	for (int i = 0; i < t; i++)
	{
		solve();
	}

	return 0;
}


//#include "pch.h"
#include <iostream>
#include <vector>
#include <sstream>
#include <algorithm>
#include <string>

int main()
{
	int q;
	std::ostringstream os;
	std::cin >> q;
	for (int i = 0; i < q; i++)
	{
		bool isGood = false;
		int rem = 0;
		int n;
		std::cin >> n;
		for (int j = 0; j < n; j++)
		{
			std::string in;
			std::cin >> in;
			if ((in.length() % 2 == 1)||(isGood)) { isGood = true; }
			else
			{
				for (int k = 0; k < in.length(); k++)
				{
					if (in[k] == '1')
					{
						rem = (rem + 1) % 2;
					}
				}
			}
		}
		if (isGood) { rem = 0; }
		os << n - rem << std::endl;
	}
	std::cout << os.str();
}


#include <iomanip>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <ctime>
#include <cstdio>
#include <cmath>
#include <queue>
#include <bitset>
#include <string>

#define ll long long
#define mp make_pair
#define pb push_back

using namespace std;

const int N = 300010;
const int MOD = 1e9+7;
const ll mx = 4e18;

int q;
int n, len[N];

int main() {
    cin >> q;
    while (q--) {
        int cnt[2] = {0, 0};
        cin >> n;
        for (int i = 0; i < n; i++) {
            string s;
            cin >> s;
            len[i] = s.length();
            for (int j = 0; j < s.length(); j++) cnt[s[j] - '0']++;
        }
        int p[2] = {cnt[0] & 1, cnt[1] & 1};
        if (p[0] < p[1]) swap(p[0], p[1]);
        int ans = n - 1;
        bool ok = false;
        for (int i = 0; i < n; i++) {
            if (len[i] % 2 != 0) p[0] ^= 1;
            if (p[0] < p[1]) swap(p[0], p[1]);
        }
        if (p[0] == 0 && p[1] == 0) ans++;
        printf("%d\n", ans);
    }
	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>

using namespace std;
#define ll long long

int main()
{
	int q;
	cin >> q;

	int n;
	string number;
	vector<string> nums;
	vector<int> counts;
	int polis;
	bool found;
	for (int i = 0; i < q; i++)
	{
		cin >> n;
		polis = 0;
		found = false;
		for (int j = 0; j < n; j++)
		{
			cin >> number;
			nums.push_back(number);
		}

		for (int j = 0; j < n; j++)
		{
			counts.resize(3);
			if (nums[j].length() % 2 == 1) {
				cout << n << endl;
				found = true;
				break;
			}
			for (int k = 0; k < nums[j].length(); k++)
			{
				counts[nums[j][k]-'0']++;
			}
			if (counts[0] % 2 == 1 && counts[1] % 2 == 1)
				polis++;
			counts.clear();
		}

		if (!found) {
			if (polis % 2 == 1)
				cout << n - 1 << endl;
			else cout << n << endl;;
		}
		nums.clear();
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <string>
#include <iomanip>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

typedef long long li;
typedef unsigned long long uli;
typedef pair<int, int> pii;
typedef long double ld;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fr first
#define sc second
#define pb push_back
#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define forb(i, n) for(int i = int(n) - 1; i >= 0; --i)

const int INF = 1e9 + 1000;
const li INF64 = 1e15 + 1000;
const int M = 2 * 100 * 1000 + 100;
const int N = 2 * 1000 * 1000 + 10;
const int MOD = 1e6 + 3;
const double EPS = 1e-9;
const double PI = 3.14159265359;

li gcd(li a, li b) {
	return a == 0 ? b : gcd(b % a, a);
}

int sign(int x)
{
	return (x > 0) - (x < 0);
}
vector<int> d;
vector<int> v;
vector<bool> used;

int f(int x, int c)
{
	used[x] = true;
	d[x] = c;
	if (!used[v[x]])
		d[x] = f(v[x], c + 1);
	return d[x];
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int q;
	cin >> q;

	forn(qq, q)
	{
		int n;
		cin >> n;

		int c1 = 0;
		int c0 = 0;
		int mle = 0;
		int se = 0;
		int mln = 0;
		int sn = 0;

		int ss = 0;

		forn(i, n)
		{
			string s;
			cin >> s;

			forn(j, s.size())
				if (s[j] == '1')
					c1++;
				else
					c0++;

			if (s.size() % 2 == 0)
			{
				mle = max<int>(mle, s.size());
				se += s.size();
			}
			else
			{
				mln = max<int>(mln, s.size());
				sn += s.size();
			}

		}

		ss = c1 + c0;

		int ans = n - 1;

		if (!(sn == 0 && c1 % 2 == 1 && c0 % 2 == 1))
			ans++;

		cout << ans << endl;
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
#include <cmath>
#include <functional>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <ctime>
#include <chrono>
#include <climits>
#define mp make_pair
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define pb(x) push_back(x);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define MOD 998244353  //(1000*1000*1000+7)
#define inf1 2e9
#define inf2 2e18
default_random_engine generator;
uniform_int_distribution<int> distribution(1, INT_MAX);

vector<vector<long long> > one(int sz) {
	vector<vector<long long> > ret;
	ret.resize(sz);
	for (int i = 0; i < ret.size(); i++) {
		ret[i].resize(sz);
		for (int j = 0; j < ret.size(); j++) {
			ret[i][j] = (i == j);
		}
	}
	return ret;
}

vector<vector<long long> > mult(vector<vector<long long> > a, vector<vector<long long> > b) {
	vector<vector<long long > > ret;
	ret.resize(a.size());
	for (int i = 0; i < ret.size(); i++) {
		ret[i].resize(a.size());
		for (int j = 0; j < ret.size(); j++) {
			ret[i][j] = 0;
		}
	}
	for (int k = 0; k < ret.size(); k++) {
		for (int i = 0; i < a.size(); i++) {
			for (int j = 0; j < b.size(); j++) {
				ret[i][j] = (ret[i][j] + a[i][k] * b[k][j]);
				ret[i][j] %= MOD;
			}
		}
	}
	return ret;
}

vector<vector<long long> > pw(vector<vector<long long> > a, long long b) {
	if (b == 0)
		return one((int)a.size());
	if (b % 2)
		return mult(a, pw(a, b - 1));
	return pw(mult(a, a), b / 2);
}

ll my_rand(ll a = 0, ll b = INT_MAX) {
	return a + distribution(generator) % b;
}

inline int mul(int a, int b) {
	return int(a * 1ll * b % MOD);
}

inline int norm(int a) {
	if (a >= MOD)
		a -= MOD;
	if (a < 0)
		a += MOD;
	return a;
}

inline int binPow(int a, int k) {
	int ans = 1;
	while (k > 0) {
		if (k & 1)
			ans = mul(ans, a);
		a = mul(a, a);
		k >>= 1;
	}
	return ans;
}

inline int subtract(int a, int b) {
	return norm(a - b);
}

inline int sum(int a, int b) {
	return int((a + b) % MOD);
}

inline int inv(int a) {
	return binPow(a, MOD - 2);
}

ll ceil_int(ll a, ll b) {
	return a / b + (a % b != 0);
}

ll gcd(ll a, ll b) {
	if (a == 0)return b;
	return gcd(b % a, a);
}

ll lcm(ll a, ll b) {
	return (a * b) / gcd(a, b);
}

int main() {
	generator.seed(chrono::system_clock::now().time_since_epoch().count());
	cin.sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		int n;
		cin >> n;
		vector<int>zeros(n);
		vector<int>ones(n);
		vector<string>w(n);
		for (int j = 0; j < n; j++) {
			string s;
			cin >> s;
			w[j] = s;
			for (int q = 0; q < s.length(); q++) {
				if (s[q] == '0') {
					zeros[j]++;
				}
				else {
					ones[j]++;
				}
			}
		}
		vector<int>used(n);
		int ans = 0;
		vector<int>cases(4);
		for (int j = 0; j < n; j++) {
			if (ones[j] % 2 == 0 && zeros[j] % 2 == 0) {
				cases[0]++;
			}
			if (ones[j] % 2 == 1 && zeros[j] % 2 == 0) {
				cases[1]++;
			}
			if (ones[j] % 2 == 0 && zeros[j] % 2 == 1) {
				cases[2]++;
			}
			if (ones[j] % 2 == 1 && zeros[j] % 2 == 1) {
				cases[3]++;
			}
		}
		int fixed_pairs = cases[3] / 2 * 2;
		cases[3] %= 2;
		ans = cases[0] + cases[1] + cases[2] + fixed_pairs + min(cases[1] + cases[2], cases[3]);
		cout << ans << endl;
	}

	return 0;
}


//1251
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
int q, n, a[2];
std::string s[50];
int main ()
{
  std::cin >> q;
  while (q--)
  {
    std::cin >> n;
    std::vector<int> v;
    for (int i = 0; i < n; ++i)
    {
      std::cin >> s[i];
      for (int j = 0; j < s[i].size (); ++j)
        a[s[i][j] - '0']++;
      v.push_back (s[i].size ());
    }
    std::sort (v.begin (), v.end ());
    int ans = 0;
    for (int el : v)
    {
      if (el % 2)
      {
        for (int i = 0; i < 2; ++i)
          if (a[i] % 2)
          {
            a[i]--;
            el--;
            break;
          }
        if (el % 2)
          for (int i=0;i<2;++i)
            if (a[i] > 0)
            {
              a[i]--;
              el--;
              break;
            }
      }
      for (int i = 0; i < 2 && el > 0; ++i)
        if (a[i] > 1)
        {
          int de = std::min (a[i] / 2 * 2, el);
          a[i] -= de;
          el -= de;
        }
      if (el)
        break;
      else
        ++ans;
    }
    std::cout << ans << "\n";
  }
}


//1251
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
int q, n, a[2];
std::string s[50];
int main ()
{
  std::cin >> q;
  while (q--)
  {
    std::cin >> n;
    std::vector<int> v;
    a[0] = 0;
    a[1] = 0;
    for (int i = 0; i < n; ++i)
    {
      std::cin >> s[i];
      for (int j = 0; j < s[i].size (); ++j)
        a[s[i][j] - '0']++;
      v.push_back (s[i].size ());
    }
    std::sort (v.begin (), v.end ());
    int ans = 0;
    for (int el : v)
    {
      if (el % 2)
      {
        for (int i = 0; i < 2; ++i)
          if (a[i] % 2)
          {
            a[i]--;
            el--;
            break;
          }
        if (el % 2)
          for (int i=0;i<2;++i)
            if (a[i] > 0)
            {
              a[i]--;
              el--;
              break;
            }
      }
      for (int i = 0; i < 2 && el > 0; ++i)
        if (a[i] > 1)
        {
          int de = std::min (a[i] / 2 * 2, el);
          a[i] -= de;
          el -= de;
        }
      if (el)
        break;
      else
        ++ans;
    }
    std::cout << ans << "\n";
  }
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <math.h>
#include <string>

using namespace std;

int main() {
	int Q;
	scanf("%d", &Q);
	int n;
	for (int t = 0; t < Q; t++) {
		scanf("%d", &n);
		cin.ignore(256,'\n');
		vector<int> length(n, 0);
		int onecount = 0;
		string input;
		for (int i = 0; i < n; i++) {
			getline(cin, input);
			for (int i = 0; i < input.length(); i++) {
				if (input[i] == '1') {
					onecount++;
				}
			}
			length[i] = input.length();
		}
		int output = 0;
		bool odd = false;
		for (int i = 0; i < n; i++) {
			if (length[i] % 2 == 0) {
				if (length[i] <= onecount) {
					onecount -= length[i];
				}
				else {
					if (onecount > 1) {
						onecount = onecount % 2;
					}
				}
			}
			if (length[i] % 2 == 1) {
				odd = true;
			}
		}
		if (odd == false && onecount == 1) {
			printf("%d\n", n - 1);
		}
		else {
			printf("%d\n", n);
		}
	}
	return 0;
}