#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;

struct node
{
    int x,y,step;
    bool operator < (const node a) const{
    return step>a.step;
    }
};

char a[1005][1005];
bool vis[1005][1005];
int n,m,k;
int x1,x2,y1,y2;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
void bfs()
{
    priority_queue<node>q;
    q.push({x1,y1,0});
    vis[x1][y1]=1;
    while(!q.empty())
    {
        node p=q.top();
        q.pop();
        int i;
        for(i=0;i<4;i++)
        {
            int cx=p.x+dx[i];
            int cy=p.y+dy[i];
            if(cx<1||cx>n||cy<1&&cy>m&&a[cx][cy]=='#')
                continue;
            if(i==0)
            {
                int j;
                for(j=1;j<=k;j++)
                {
                    int yy=p.y+j;
                    if(yy>m||a[p.x][yy]=='#') break;
                     if(vis[p.x][yy]==1) continue;
                    q.push({p.x,yy,p.step+1});
                    vis[p.x][yy]=1;
                    if(p.x==x2&&yy==y2)
                    {
                        printf("%d",p.step+1);
                        return;
                    }
                }
            }
            if(i==1)
            {
                int j;
                for(j=1;j<=k;j++)
                {
                    int yy=p.y-j;
                    if(yy<1||a[p.x][yy]=='#') break;
                     if(vis[p.x][yy]==1) continue;

                    q.push({p.x,yy,p.step+1});
                    vis[p.x][yy]=1;
                    if(p.x==x2&&yy==y2)
                    {
                        printf("%d",p.step+1);
                        return;
                    }
                }
            }
            if(i==2)
            {
                int j;
                for(j=1;j<=k;j++)
                {
                    int xx=p.x+j;
                    if(xx>n||a[xx][p.y]=='#') break;
                     if(vis[xx][p.y]==1) continue;
                    q.push({xx,p.y,p.step+1});
                    vis[xx][p.y]=1;
                    if(xx==x2&&p.y==y2)
                    {
                        printf("%d",p.step+1);
                        return;
                    }
                }
            }
            if(i==3)
            {
                int j;
                for(j=1;j<=k;j++)
                {
                    int xx=p.x-j;
                    if(xx<1||a[xx][p.y]=='#') break;
                     if(vis[xx][p.y]==1) continue;
                    q.push({xx,p.y,p.step+1});
                    vis[xx][p.y]=1;
                    if(xx==x2&&p.y==y2)
                    {
                        printf("%d",p.step+1);
                        return;
                    }
                }
            }
        }
    }
    printf("-1");
}
int main()
{
    scanf("%d%d%d",&n,&m,&k);
    int i,j;
    for(i=1;i<=n;i++)
        scanf("%s",(a[i]+1));
    scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
    if(x1==x2&&y1==y2) printf("0");
    else bfs();
}


#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define MAXN 1005
#define Int register LL
#define INF 0x3f3f3f3f3f3f3f3f
using namespace std;
inline LL Abs(LL x)
{
	if (x > 0)
		return x;
	return - x;
}
inline LL Min(LL x,LL y)
{
	return x < y ? x : y;
}
inline LL Max(LL x,LL y)
{
	return x > y ? x : y;
}
inline void read(LL &x)
{
	x = 0;
	LL f = 1;
	char s = getchar();
	while (s < '0' || s > '9')
	{
		if (s == '-')
			f = -1;
		s = getchar();
	}
	while (s >= '0' && s <= '9')
	{
		x = (x << 3) + (x << 1) + (s ^ 48);
		s = getchar();
	}
	x *= f;
}
char Maze[MAXN][MAXN];
LL Dir[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}, n, m, k;
bool Outside(LL x,LL y)
{
	if (x < 1 || x > n || y < 1 || y > m || Maze[x][y] == '#')
		return 1;
	return 0;
}
struct node
{
	LL x, y, Time;
	node(){}
	node(LL X,LL Y,LL TIME)
	{
		x = X;
		y = Y;
		Time = TIME;
	}
};
LL dp[MAXN][MAXN];
bool Vis[MAXN][MAXN][4], Pan[MAXN][MAXN];
int main()
{
	read( n ); read( m ); read( k );
	for (Int i = 1; i <= n; ++ i)
		scanf("%s", Maze[i] + 1);
	LL sx, sy, tx, ty;
	read( sx ); read( sy ); read( tx ); read( ty );
	queue<node> Q;
	Q.push(node(sx, sy, 0));
	LL Ans = -1;
	memset(dp, 0x3f, sizeof dp);
	while (! Q.empty())
	{
		node Now = Q.front();
		Q.pop();
		if ( Pan[Now.x][Now.y] )
			continue;
		Pan[Now.x][Now.y] = 1;
		if (Now.x == tx && Now.y == ty)
		{
			Ans = Now.Time;
			break;
		}
		for (Int i = 0; i < 4; ++ i)
		{
			for (Int j = 1; j <= k; ++ j)
			{
				LL tox = Now.x + Dir[i][0] * j;
				LL toy = Now.y + Dir[i][1] * j;
				if ( Outside(tox, toy) )
					break;
				if ( Vis[tox][toy][i] )
					continue;
				if (Now.Time + 1 >= dp[tox][toy])
					continue;
				dp[tox][toy] = Now.Time + 1;
				Vis[tox][toy][i] = 1;
				Q.push(node(tox, toy, Now.Time + 1));
			}
		}
	}
	printf("%lld", Ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1010,M=10000010;
const int dx[]={-1,1,0,0};
const int dy[]={0,0,-1,1};
int n,m,k,ans,g[N][N],d[N][N];
int sx,sy,ex,ey,l,r;
bool vis[N][N];
struct node{
	int x,y;
}q[M];
void bfs(){
	while(l<=r){
		if(q[l].x==ex&&q[l].y==ey)return;
		for(int i=0;i<4;i++)
			for(int j=1;j<=k;j++){
				int tx=q[l].x+j*dx[i];int ty=q[l].y+j*dy[i];
				if(tx<1||ty<1||tx>n||ty>m||g[tx][ty]||vis[tx][ty]&(1<<i))break;
				int flag=0;if(!vis[tx][ty])flag=1;vis[tx][ty]|=(1<<i);
				if(flag!=0){q[++r].x=tx;q[r].y=ty;d[tx][ty]=d[q[l].x][q[l].y]+1;}
			}
		l++;
	}
	puts("-1");
}
int main(){
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			char c;cin>>c;
			if(c=='#')g[i][j]=1;
		}
	scanf("%d%d%d%d",&sx,&sy,&ex,&ey);
	l=r=1;
	q[l].x=sx;
	q[l].y=sy;
	vis[sx][sy]=(1<<4)-1;
	bfs();
	if(vis[ex][ey])printf("%d\n",d[ex][ey]);
	else puts("-1");
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int n,m,k,way[4][2]={{-1,0},{0,1},{1,0},{0,-1}};
bool map[1000][1000],vis[1000][1000];
struct Q
{
  int i,j;
  int n;
}q[1000000];
bool bgo(int i,int j)
{
  if(i<0||i>=n||j<0||j>=m||map[i][j]||vis[i][j]) return 0;
  return 1;
}
int bfs(int fn,int fm,int ln,int lm)
{
  int head=0,tail=0;
  fn--; fm--; ln--; lm--;
  q[head].i=fn;
  q[head].j=fm;
  q[head].n=0;
  vis[q[head].i][q[head].j]=1;
  if(q[tail].i==ln&&q[tail].j==lm) return q[tail].n;
  while(head<=tail)
  {
  	for(int i=0;i<4;i++)
  	{
  	  int j=1;
  	  while(bgo(q[head].i+(j*way[i][0]),q[head].j+(j*way[i][1]))&&j<=k)
  	  {
  	  	q[++tail].i=q[head].i+(j*way[i][0]);
  	  	q[tail].j=q[head].j+(j*way[i][1]);
  	  	q[tail].n=q[head].n+1;
  	  	vis[q[tail].i][q[tail].j]=1;
  	  	if(q[tail].i==ln&&q[tail].j==lm) return q[tail].n;
  	  	j++;
	  }
    }
	head++;
  }
  return -1;
}
int main()
{
  int fn,fm,ln,lm;
  scanf("%d %d %d",&n,&m,&k);
  char init;
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
    {
      cin>>init;
      if(init=='#') map[i][j]=1;
	}
  scanf("%d %d %d %d",&fn,&fm,&ln,&lm);
  printf("%d\n",bfs(fn,fm,ln,lm));
  return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;

#define M 1005

struct node {
    int x, y, step;
    node (){};
    node (int X, int Y, int STEP){
        x = X;
        y = Y;
        step = STEP;
    }
};
int n, m, k, G[M][M], sx, sy, tx, ty, ans = -1;
int dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
bool vis[M][M];

bool check (int x, int y){
    if (x >= 1 && x <= n && y >= 1 && y <= m && G[x][y] != '#')
        return 1;
    return 0;
}
void bfs (){
    queue <node> Q;
    Q.push (node (sx, sy, 0));
    vis[sx][sy] = 1;
    while (! Q.empty ()){
        node f = Q.front ();
        Q.pop ();
        for (int i = 0; i < 4; i ++){
            int tox, toy;
            for (int j = 1; j <= k; j ++){;
                tox = dir[i][0] * j + f.x;
                toy = dir[i][1] * j + f.y;
                if (! check (tox, toy))
                    break;
                if (check (tox, toy) && ! vis[tox][toy]){
                    vis[tox][toy] = 1;
                    Q.push (node (tox, toy, f.step + 1));
                    if (tox == tx && toy == ty){
                        ans = f.step + 1;
                        return ;
                    }
                }
            }
        }
    }
}
int main (){
    scanf ("%d %d %d", &n, &m, &k);
    for (int i = 1; i <= n; i ++){
        scanf ("\n");
        for (int j = 1; j <= m; j ++)
            scanf ("%c", &G[i][j]);
    }
    scanf ("%d %d %d %d", &sx, &sy, &tx, &ty);
    bfs ();
    printf ("%d\n", ans);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define x first
#define y second
using namespace std;

const int MAXN = 1005, INF =0x3f3f3f3f;
const int DIR[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

int n, m, k, x1, y1, x2, y2;
char mp[MAXN][MAXN];
int dist[MAXN][MAXN];
bool in[MAXN][MAXN];
queue<pair<int, int> > q;

bool ok(int x, int y)
{
    return (1 <= x && x <= n && 1 <= y && y <= m);
}

void bfs()
{
    memset(in, false, sizeof(in));
    pair<int, int> st, u, v;
    st.x = x1; st.y = y1;
    q.push(st);
    in[x1][y1] = true;
    while (!q.empty()) {
        u = q.front(); q.pop();
        in[u.x][u.y] = false;
        for (int d = 0; d <= 3; d++) {
            v = u;
            for (int i = 1; i <= k; i++) {
                v.x += DIR[d][0]; v.y += DIR[d][1];
                if (ok(v.x, v.y) && mp[v.x][v.y] == '.' && dist[v.x][v.y] >= dist[u.x][u.y] + 1) {
                    dist[v.x][v.y] = dist[u.x][u.y] + 1;
                      q.push(v); in[v.x][v.y] = true;
                }
                else
                    break;
            }
        }
    }
}

int main()
{
    scanf("%d %d %d", &n, &m, &k);
    char buff[MAXN];
    for (int i = 1; i <= n; i++) {
        scanf("%s", buff);
        for (int j = 1; j <= m; j++) mp[i][j] = buff[j - 1];
    }
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    memset(dist, 0x3f, sizeof(dist));
    dist[x1][y1] = 0;
    bfs();
    if (dist[x2][y2] == INF)
        printf("-1");
    else
        printf("%d", dist[x2][y2]);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define x first
#define y second
using namespace std;

const int MAXN = 1005, INF =0x3f3f3f3f;
const int DIR[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

int n, m, k, x1, y1, x2, y2;
char mp[MAXN][MAXN];
int dist[MAXN][MAXN];
bool in[MAXN][MAXN];
queue<pair<int, int> > q;

bool ok(int x, int y)
{
    return (1 <= x && x <= n && 1 <= y && y <= m);
}

void bfs()
{
    memset(in, false, sizeof(in));
    pair<int, int> st, u, v;
    st.x = x1; st.y = y1;
    q.push(st);
    in[x1][y1] = true;
    while (!q.empty()) {
        u = q.front(); q.pop();
        in[u.x][u.y] = false;
        for (int d = 0; d <= 3; d++) {
            v = u;
            for (int i = 1; i <= k; i++) {
                v.x += DIR[d][0]; v.y += DIR[d][1];
                if (ok(v.x, v.y) && mp[v.x][v.y] == '.' && dist[v.x][v.y] >= dist[u.x][u.y] + 1) {
                    dist[v.x][v.y] = dist[u.x][u.y] + 1;
                    q.push(v);
                }
                else
                    break;
            }
        }
    }
}

int main()
{
    scanf("%d %d %d", &n, &m, &k);
    char buff[MAXN];
    for (int i = 1; i <= n; i++) {
        scanf("%s", buff);
        for (int j = 1; j <= m; j++) mp[i][j] = buff[j - 1];
    }
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    memset(dist, 0x3f, sizeof(dist));
    dist[x1][y1] = 0;
    bfs();
    if (dist[x2][y2] == INF)
        printf("-1");
    else
        printf("%d", dist[x2][y2]);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define x first
#define y second
using namespace std;

const int MAXN = 1005, INF =0x3f3f3f3f;
const int DIR[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

int n, m, k, x1, y1, x2, y2;
char mp[MAXN][MAXN];
int dist[MAXN][MAXN];
bool in[MAXN][MAXN];
queue<pair<int, int> > q;

bool ok(int x, int y)
{
    return (1 <= x && x <= n && 1 <= y && y <= m);
}

void bfs()
{
    memset(in, false, sizeof(in));
    pair<int, int> st, u, v;
    st.x = x1; st.y = y1;
    q.push(st);
    in[x1][y1] = true;
    while (!q.empty()) {
        u = q.front(); q.pop();
        in[u.x][u.y] = false;
        for (int d = 0; d <= 3; d++) {
            v = u;
            for (int i = 1; i <= k; i++) {
                v.x += DIR[d][0]; v.y += DIR[d][1];
                if (ok(v.x, v.y) && mp[v.x][v.y] == '.' )
				{

                    if (dist[v.x][v.y] > dist[u.x][u.y] + 1&&!in[v.x][v.y]) {dist[v.x][v.y] = dist[u.x][u.y] + 1;q.push(v); in[v.x][v.y] = true;}
                }
                else
                    break;
            }
        }
    }
}

int main()
{
    scanf("%d %d %d", &n, &m, &k);
    char buff[MAXN];
    for (int i = 1; i <= n; i++) {
        scanf("%s", buff);
        for (int j = 1; j <= m; j++) mp[i][j] = buff[j - 1];
    }
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    memset(dist, 0x3f, sizeof(dist));
    dist[x1][y1] = 0;
    bfs();
    if (dist[x2][y2] == INF)
        printf("-1");
    else
        printf("%d", dist[x2][y2]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,m,k;
int x1,y1,x2,y2,x3,y3;
int x,y;
char tu[1010][1010];
int biao[1010][1010];
int ans;
struct dian
{
	int a;int b;
}temp;
int f1[4]={0,0,1,-1};
int f2[4]={1,-1,0,0};
void work()
{
	biao[x1][y1]=0;//
	queue<struct dian>qu;
	temp.a=x1;temp.b=y1;
	qu.push(temp);
	while(!qu.empty())
	{
		temp=qu.front();
		qu.pop();
		x=temp.a;
		y=temp.b;
		if(x==x2&&y==y2)
		break;
		for(int i=0;i<4;i++)
		for(int j=1;j<=k;j++)
		{
		x3=x+f1[i]*j;
		y3=y+f2[i]*j;
		if(x3>n||x3<1||y3>m||y3<1||tu[x3][y3]=='#'||biao[x3][y3]!=1e8)
		break;
				temp.a=x3;
				temp.b=y3;
				qu.push(temp);
				biao[x3][y3]=biao[x][y]+1;
	  }

	}
}
int main()
{
scanf("%d %d %d",&n,&m,&k);
for(int i=1;i<=n;i++)
{
getchar();
for(int j=1;j<=m;j++)
{
scanf("%c",&tu[i][j]);
biao[i][j]=1e8;
}
}
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);//
work();
if(biao[x2][y2]!=1e8)
printf("%d",biao[x2][y2]);
else printf("-1");
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,m,k;
int x1,y1,x2,y2,x3,y3;
int x,y;
char tu[1050][1050];
int biao[1050][1050];
int ans;
struct dian
{
	int a;int b;
}temp;
int f1[4]={0,0,1,-1};
int f2[4]={1,-1,0,0};
void work()
{
	biao[x1][y1]=0;//
	queue<struct dian>qu;
	temp.a=x1;temp.b=y1;
	qu.push(temp);
	while(!qu.empty())
	{
		temp=qu.front();
		qu.pop();
		x=temp.a;
		y=temp.b;
		if(biao[x2][y2]!=1e8)
		break;
		for(int i=0;i<4;i++)
		for(int j=1;j<=k;j++)
		{
		x3=x+f1[i]*j;
		y3=y+f2[i]*j;
		if(x3>n||x3<1||y3>m||y3<1||tu[x3][y3]=='#'||biao[x3][y3]!=1e8)
		break;
				temp.a=x3;
				temp.b=y3;
				qu.push(temp);
				biao[x3][y3]=biao[x][y]+1;
	  }

	}
}
int main()
{
scanf("%d %d %d",&n,&m,&k);
for(int i=1;i<=n;i++)
{
getchar();
for(int j=1;j<=m;j++)
{
scanf("%c",&tu[i][j]);
biao[i][j]=1e8;
}
}
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);//
if(x1==x2&&y1==y2)
{
printf("0");
return 0;}
work();
if(biao[x2][y2]!=1e8)
printf("%d",biao[x2][y2]);
else printf("-1");
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q, n;
	string str[60];
	cin>>q;
	while(q--){
		cin>>n;
		int a[60];
		int o=0, z=0;
		for(int i=1; i<=n; i++){
			cin>>str[i];
			a[i]=str[i].length();
			for(int j=0; j<str[i].length(); j++){
				if(str[i][j]=='1')o++;
				else z++;
			}
		}
		int num=0;
		for(int i=1; i<=n; i++){
			if(a[i]%2)num++;
		}
		if(num%2==0&&o%2)cout<<n-1;
		else cout<<n;
		cout<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q, n;
	cin>>q;
	while(q--){
		cin>>n;
		string str[60];
		int a[60];
		int o=0, z=0;
		for(int i=1; i<=n; i++){
			cin>>str[i];
			a[i]=str[i].length();
			for(int j=0; j<str[i].length(); j++){
				if(str[i][j]=='1')o++;
				else z++;
			}
		}
		int num=0;
		for(int i=1; i<=n; i++){
			if(a[i]%2)num++;
		}
		//cout<<"1:"<<o<<" 0:"<<z<<" num:"<<num<<endl;
		if(num%2==0&&o%2==1)cout<<n-1;
		else cout<<n;
		cout<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q, n;
	string str[60];
	cin>>q;
	while(q--){
		cin>>n;
		int a[60];
		int o=0, z=0;
		for(int i=1; i<=n; i++){
			cin>>str[i];
			a[i]=str[i].length();
			for(int j=0; j<str[i].length(); j++){
				if(str[i][j]=='1')o++;
				else z++;
			}
		}
		int num=0;
		for(int i=1; i<=n; i++){
			if(a[i]%2)num++;
		}
		//cout<<"1:"<<o<<" 0:"<<z<<" num:"<<num<<endl;
		if(num%2==0&&o%2==1)cout<<n-1;
		else cout<<n;
		cout<<endl;
	}
}


/*#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q, n;
	cin>>q;
	while(q--){
		cin>>n;
		string str;
		int num=0;
		int o=0, z=0;
		for(int i=1; i<=n; i++){
			cin>>str;
			if(str.length()%2)num++;
			for(int j=0; j<str.length(); j++){
				if(str[j]=='1')o++;
				else z++;
			}
		}

		//int num=0;
		//for(int i=1; i<=n; i++){
		//	if(a[i]%2)num++;
		//}
		//cout<<"1:"<<o<<" 0:"<<z<<" num:"<<num<<endl;
		if(num%2==0&&o%2==1)cout<<n-1;
		else cout<<n;
		cout<<endl;
	}
}*/
#include <bits/stdc++.h>

using namespace std;
int main()
{
    int q;
    cin>>q;
    while(q--)
    {
        int n;
        cin>>n;
        int num1 = 0,num2 = 0;
        int len1 = 0,len0 = 0;
        for(int i = 0; i < n; i++){
            string s;
            cin>>s;
            int len= s.length();
            if(len%2)
                len1++;
            else
                len0++;
            for(int j = 0; j <s.length(); j++){
                if(s[j]=='1')
                    num1++;
                else
                    num2++;
            }
        }
        if((!len1%2)&&num1%2){
            cout<<n-1<<endl;
        }
        else
        {
            cout<<n<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q, n;
	cin>>q;
	while(q--){
		cin>>n;
		string str;
		int num=0;
		int o=0, z=0;
		for(int i=1; i<=n; i++){
			cin>>str;
			if(str.length()%2)num++;
			for(int j=0; j<str.length(); j++){
				if(str[j]=='1')o++;
				else z++;
			}
		}

		//int num=0;
		//for(int i=1; i<=n; i++){
		//	if(a[i]%2)num++;
		//}
		//cout<<"1:"<<o<<" 0:"<<z<<" num:"<<num<<endl;
		if(num%2==0&&o%2==1)cout<<n-1;
		else cout<<n;
		cout<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[5],n;
	int T;
	scanf("%d",&T);
	while (T--)
	{
		scanf("%d",&n);
		string str;
		int n1=0;
		bool flag=false;
		for (int i=1;i<=n;i++)
		{
			cin >>str;
			int l=str.size();
			if (l&1) flag=true;
			for (int j=0;j<l;j++)
				if (str[j]=='1') n1++;
		}
		if ((n1%2==1)&&!flag) printf("%d\n",n-1);
		else printf("%d\n",n);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int T, n, ans;

char str[100];

int len[100];

int num[2], cp, sing;

void check(int nowcp, int nowsing) {
    if (sing >= nowsing && cp >= nowcp) {
        sing -= nowsing;
        cp -= nowcp;
        ans ++ ;
        return ;
    }
    if (cp < nowcp) {
        return ;
    }
    if (cp > nowcp && sing < nowsing) {
        cp -= 1;
        sing += 2;
        cp -= nowcp;
        sing -= nowsing;
        ans ++ ;
        return ;
    }
}

int main() {
    scanf("%d", &T);
    while (T -- ) {
        num[1] = 0, num[0] = 0;
        ans = 0;
        sing = cp = 0;
        scanf("%d", &n);
        for (int i = 1; i <= n; i ++ ) {
            scanf("%s", str + 1);
            len[i] = strlen(str + 1);
            for (int j = 1; j <= len[i]; j ++ ) {
                if (str[j] == '1') {
                    num[1] ++ ;
                }
                else {
                    num[0] ++ ;
                }
            }
        }
        cp = num[1] / 2 + num[0] / 2;
        sing = (num[1] + num[0]) - cp * 2;
        sort(len + 1, len + 1 + n);
        for (int i = 1; i <= n; i ++ ) {
            int nowcp = len[i] / 2;
            int nowsing = len[i] - (nowcp * 2);
            check(nowcp, nowsing);
        }
        cout << ans << endl;
    }
}


#include<cstdio>
#include<cstdlib>
#define rnt register int
using namespace std;
int T,n,f[2];
char s[502];
int main()
{
	scanf("%d",&T);
	for(;T;--T)
	{
		scanf("%d",&n);
		int flag=0;f[0]=f[1]=0;
		for(rnt i=0;i<n;i=-~i)
		{
			scanf("%s",s);
			rnt j=0;
			for(;s[j];j=-~j)
				++f[s[j]-'0'];
			if(j&1) flag=1;
		}
		if(!(f[0]&1)) flag=1;
		if(flag) printf("%d\n",n);
		else printf("%d\n",n-1);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q,n,js,num,l,i,j,k;
	scanf("%d",&q);
	string s;
	for(i=0;i<q;i++)
	{
		scanf("%d",&n);
		num=0;
		js=0;
		for(k=1;k<=n;k++)
        {
			cin>>s;
			l=s.size();
			if(l%2==1) js++;
			for(j=0;j<l;j++)
            {
				if(s[j]=='1') num++;
            }
        }
		if(num%2==1)
        {
			if(js>=1) printf("%d\n",n);
			else printf("%d\n",n-1);
		}
		else printf("%d\n",n);

	}
	return 0;
}


#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
    int t,n;
    char temp[59];
    scanf("%d",&t);
    while(t--)
    {
        int cnt1=0,cnt2=0;
        int cnt1len=0,cnt2len=0;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
            scanf("%s",temp);
        int len=strlen(temp);
        if(len%2==1)cnt1len++;
        else cnt2len++;
        for(int i=0;i<len;i++)
        {
            if(temp[i]=='1')cnt1++;
            else cnt2++;
        }
        if((cnt1len%2==1&&(cnt1+cnt2)%2==1)||(cnt1len%2==0&&(cnt1+cnt2)%2==0))
            printf("%d\n",n);
        else printf("%d\n",n-1);
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<set>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;
char s[101010];
int T,n,ans,sum;
int main()
{
	scanf("%d",&T);
	while(T --){
		ans = sum  = 0;
		scanf("%d",&n);
		for(int i = 1;i <= n ;i ++){
			int tmp = 0;
			scanf("%s",s + 1);
			int len = strlen(s + 1);
			if(len % 2 == 1){ans ++;continue;}
			for(int j = 1;j <= len;j ++){
				if(s[j] == '1')tmp ++;
			}
			if(tmp % 2 == 0)ans ++;
			else sum ++;
		}
		cout<<ans + sum /2 <<endl;
	}
	return 0;
}
/*
long long
线段树四倍
写代码时请注意:
	1.是否要开Long Long?数组边界处理好了么?
	2.实数精度有没有处理?
	3.特殊情况处理好了么?
	4.做一些总比不做好.
思考提醒:
	1.最大值和最小值问题可不可以用二分答案?
	2.有没有贪心策略?否则能不能dp?
*/


#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=(int)b;++i)
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define F first
#define S second
#define ll long long
#define mp make_pair
#define lowbit(x) ((x)&(-x))

int main()
{

    int t;cin>>t;
    while(t--)
    {
        int n;cin>>n;
        bool ok=false;
        int odd=0,even=0;
        rep(i,1,n)
        {
            string s;cin>>s;
            int len=s.size();if(len&1) ok=true;
            rep(j,0,len-1) if(s[j]=='0') even++;else odd++;
        }
        if(even&1&&odd&1&&!ok) printf("%d\n",n-1);
        else printf("%d\n",&n);
    }
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=(int)b;++i)
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define F first
#define S second
#define ll long long
#define mp make_pair
#define lowbit(x) ((x)&(-x))

int t,n;
vector<int>v;
int main()
{
    cin>>t;
    while(t--)
    {
        v.clear();
        int odd=0,even=0,ans=0;
        cin>>n;
        string s;
        rep(i,1,n)
        {
            cin>>s;
            int len=s.size();
            v.pb(len);
            rep(i,0,len-1)
            {
                if(s[i]=='0') even++;
                else odd++;
            }
        }
         sort(v.begin(),v.end());
            rep(i,0,v.size()-1)
            {
                if(odd>=v[i])
                {
                    ans++;odd-=v[i];
                    continue;
                }
                if(even>=v[i])
                {
                    ans++;even-=v[i];
                    continue;
                }

                if(odd+even>v[i])
                {
                    ans++;odd=0;even-=(v[i]-odd);
                    continue;
                }
                if((odd&1)&&(even&1)) continue;
                else ans+=1;
            }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=(int)b;++i)
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define F first
#define S second
#define ll long long
#define mp make_pair
#define lowbit(x) ((x)&(-x))

int main()
{

    int t;cin>>t;
    while(t--)
    {
        int n;cin>>n;
        bool ok=false;
        int odd=0,even=0;
        rep(i,1,n)
        {
            string s;cin>>s;
            int len=s.size();if(len&1) ok=true;
            rep(j,0,len-1) if(s[j]=='0') even++;else odd++;
        }
        if(even&1&&odd&1&&!ok) printf("%d\n",n-1);
        else printf("%d\n",n);
    }
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=(int)b;++i)
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define F first
#define S second
#define ll long long
#define mp make_pair
#define lowbit(x) ((x)&(-x))
int x;
int main()
{

    int t;cin>>t;
    while(t--)
    {
        int n;cin>>n;
        bool ok=false;
        int odd=0,even=0;
        rep(i,1,n)
        {
            string s;cin>>s;
            int len=s.size();if(len&1) ok=true;
            rep(j,0,len-1) if(s[j]=='0') even++;else odd++;
        }
        if(even&1&&odd&1&&!ok) printf("%d\n",n-1);
        else printf("%d\n",&n);
    }
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=(int)b;++i)
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define F first
#define S second
#define ll long long
#define mp make_pair
#define lowbit(x) ((x)&(-x))

int t,n;
vector<int>v;
int main()
{
    cin>>t;
    while(t--)
    {
        v.clear();
        int odd=0,even=0,ans=0;
        cin>>n;
        string s;
        rep(i,1,n)
        {
            cin>>s;
            int len=s.size();
            v.pb(len);
            rep(i,0,len-1)
            {
                if(s[i]=='0') even++;
                else odd++;
            }
            sort(v.begin(),v.end());
            rep(i,0,v.size()-1)
            {
                if(odd>=v[i])
                {
                    ans++;odd-=v[i];
                    continue;
                }
                if(even>=v[i])
                {
                    ans++;even-=v[i];
                    continue;
                }
                if(odd+even>=v[i])
                {
                    ans++;odd=0;even-=(v[i]-odd);
                    continue;
                }
            }
        }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define mod (int) 998244353
#define MOD (int) 1e9+7
#define X 1001100011100001111ll
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define int long long
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define in(x) scanf("%d", &x)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
#define vii vector<ii>
#define sz(s) s.size()
#define bits(n) __builtin_popcount(n)
#define mx 10000
const int MAXN = (int)((1e5) + 100);
int cuberoot(int x)
{
    int lo = 1, hi = min(2000000ll, x);
    while (hi - lo > 1)
    {
        int mid = (lo + hi) / 2;
        if (mid * mid * mid < x)
        {
            lo = mid;
        }
        else hi = mid;
    }
    if (hi * hi * hi <= x) return hi;
    else return lo;
}
const int dx[4] = { -1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int N =  (int)(1 * 1e6 + 10);
bool comp(pair<int, pair<int, int>> p1, pair<int, pair<int, int>> p2)
{
    if (p1.fi > p2.first) return true;
    else if (p1.se == p2.se)
    {
        if (p1.se.fi < p2.se.fi) return true;
    }
    return false;
}

long long  fact(long long n);

long long  ncr(long long  n,long long  r)
{
    return fact(n) / (fact(r) * fact(n - r));
}

long long  fact(long long  n)
{
    long long  res = 1;
    for (long long  i = 2; i <= n; i++)
        res = res * i;
    return res%1000000007;
}

const long long  a = 1000000000;

long long  nCr(long long  n,long long  r)
{
    long long  fac1 = 1,fac2=1,fac;
    for(long long  i=r; i>=1; i--,n--)
    {
        fac1 = fac1 * n;
        if(fac1%i==0)
            fac1 = fac1/i;
        else
            fac2 = fac2 * i;
    }
    fac = fac1/fac2;
    return fac%a;
}

int knapsack(int val[],int wt[],int W,int n)
{
    if(n==0 || W==0)
        return 0;

    if(wt[n-1]>W)
        return knapsack(val,wt,W,n-1);

    else
        return max(val[n-1]+knapsack(val,wt,W-wt[n-1],n-1),knapsack(val,wt,W,n-1));
}

const long long m=1000000007;

int tree[mx];

void build(int node,int tl,int tr,int arr[])
{
    if(tr==tl)
    {
        tree[node]=arr[tl];
        return;
    }
    int mid=(tr+tl)/2;

    build(2*node,tl,mid,arr);
    build(2*node+1,mid+1,tr,arr);

    tree[node]=tree[2*node]+tree[2*node+1];
}

int query_sum(int node,int tl,int tr,int l,int r)
{
    if(l>tr || r<tl)
        return 0;

    if(tl>=l && tr<=r)
        return tree[node];

    int mid=(tl+tr)/2;

    int p1=query_sum(2*node,tl,mid,l,r);
    int p2=query_sum(2*node+1,mid+1,tr,l,r);

    return p1+p2;
}

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

int lcm(int a, int b)
{
    return (a*b)/gcd(a, b);
}
int kadane(int arr[],int n)
{
    int  max_global,max_current;
    max_global=max_current=arr[0];

    for(int i=1; i<n; i++)
    {
        max_current=max(arr[i],arr[i]+max_global);
        ///cout<<"max_current= "<<max_current<<endl;

        if(max_current>max_global)
            max_global=max_current;
        ///cout<<"max_global= "<< max_global<<endl;
    }

    return max_global;
}
vector<ll>g[8],cost[8];
ll dist[8];
ll par[8];

ll bfs(ll src,ll dst)
{
    memset(dist,-1,sizeof(dist));
    par[src]=-1;
    dist[src]=0;
    queue<long long>q;
    q.push(src);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        if(u==dst)
            return dist[dst];

        for(auto v:g[u])
        {
            if(dist[v]==-1)
            {
                dist[v]=dist[u]+1;
                par[v]=u;
                q.push(v);
            }
        }
    }
}
void print_path(ll src,ll dst)
{
    vector<ll>path;
    ll u=dst;
    while(u!=-1)
    {
        path.push_back(u);
        u=par[u];
    }
    reverse(path.begin(),path.end());
    for(auto a:path)
        cout<<a<<" ";
    cout<<endl;
}
signed main()
{
    tc(t)
    {
        ll n;
        cin>>n;
        ll bad=0;
        ll odd=0;
        ll k=n;
        while(n--)
        {
            string s;
            cin>>s;
            if(s.length()%2==0)
                bad++;
            else
                odd++;
        }
        if(bad%2==1 && odd>=1)
        {
            cout<<k<<endl;
        }
        else
        {
            if(k==2 || k==1)
                cout<<k<<endl;
            else
                cout<<k-1<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define mod (int) 998244353
#define MOD (int) 1e9+7
#define X 1001100011100001111ll
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define int long long
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define in(x) scanf("%d", &x)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
#define vii vector<ii>
#define sz(s) s.size()
#define bits(n) __builtin_popcount(n)
#define mx 10000
const int MAXN = (int)((1e5) + 100);
int cuberoot(int x)
{
    int lo = 1, hi = min(2000000ll, x);
    while (hi - lo > 1)
    {
        int mid = (lo + hi) / 2;
        if (mid * mid * mid < x)
        {
            lo = mid;
        }
        else hi = mid;
    }
    if (hi * hi * hi <= x) return hi;
    else return lo;
}
const int dx[4] = { -1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int N =  (int)(1 * 1e6 + 10);
bool comp(pair<int, pair<int, int>> p1, pair<int, pair<int, int>> p2)
{
    if (p1.fi > p2.first) return true;
    else if (p1.se == p2.se)
    {
        if (p1.se.fi < p2.se.fi) return true;
    }
    return false;
}

long long  fact(long long n);

long long  ncr(long long  n,long long  r)
{
    return fact(n) / (fact(r) * fact(n - r));
}

long long  fact(long long  n)
{
    long long  res = 1;
    for (long long  i = 2; i <= n; i++)
        res = res * i;
    return res%1000000007;
}

const long long  a = 1000000000;

long long  nCr(long long  n,long long  r)
{
    long long  fac1 = 1,fac2=1,fac;
    for(long long  i=r; i>=1; i--,n--)
    {
        fac1 = fac1 * n;
        if(fac1%i==0)
            fac1 = fac1/i;
        else
            fac2 = fac2 * i;
    }
    fac = fac1/fac2;
    return fac%a;
}

int knapsack(int val[],int wt[],int W,int n)
{
    if(n==0 || W==0)
        return 0;

    if(wt[n-1]>W)
        return knapsack(val,wt,W,n-1);

    else
        return max(val[n-1]+knapsack(val,wt,W-wt[n-1],n-1),knapsack(val,wt,W,n-1));
}

const long long m=1000000007;

int tree[mx];

void build(int node,int tl,int tr,int arr[])
{
    if(tr==tl)
    {
        tree[node]=arr[tl];
        return;
    }
    int mid=(tr+tl)/2;

    build(2*node,tl,mid,arr);
    build(2*node+1,mid+1,tr,arr);

    tree[node]=tree[2*node]+tree[2*node+1];
}

int query_sum(int node,int tl,int tr,int l,int r)
{
    if(l>tr || r<tl)
        return 0;

    if(tl>=l && tr<=r)
        return tree[node];

    int mid=(tl+tr)/2;

    int p1=query_sum(2*node,tl,mid,l,r);
    int p2=query_sum(2*node+1,mid+1,tr,l,r);

    return p1+p2;
}

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

int lcm(int a, int b)
{
    return (a*b)/gcd(a, b);
}
int kadane(int arr[],int n)
{
    int  max_global,max_current;
    max_global=max_current=arr[0];

    for(int i=1; i<n; i++)
    {
        max_current=max(arr[i],arr[i]+max_global);
        ///cout<<"max_current= "<<max_current<<endl;

        if(max_current>max_global)
            max_global=max_current;
        ///cout<<"max_global= "<< max_global<<endl;
    }

    return max_global;
}
vector<ll>g[8],cost[8];
ll dist[8];
ll par[8];

ll bfs(ll src,ll dst)
{
    memset(dist,-1,sizeof(dist));
    par[src]=-1;
    dist[src]=0;
    queue<long long>q;
    q.push(src);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        if(u==dst)
            return dist[dst];

        for(auto v:g[u])
        {
            if(dist[v]==-1)
            {
                dist[v]=dist[u]+1;
                par[v]=u;
                q.push(v);
            }
        }
    }
}
void print_path(ll src,ll dst)
{
    vector<ll>path;
    ll u=dst;
    while(u!=-1)
    {
        path.push_back(u);
        u=par[u];
    }
    reverse(path.begin(),path.end());
    for(auto a:path)
        cout<<a<<" ";
    cout<<endl;
}
signed main()
{
    tc(t)
    {
        ll n;
        cin>>n;
        ll bad=0;
        ll odd=0;
        ll k=n;
        while(n--)
        {
            string s;
            cin>>s;
            if(s.length()%2==0)
                bad++;
            else
                odd++;
        }
        if(odd>=1)
        {
            if(bad%2==1)
            cout<<k<<endl;
            else if(odd==k)
            cout<<k<<endl;
            else
                cout<<k-1<<endl;
        }
        else
        {
            if(k==2)
            {
                cout<<k<<endl;
            }
            else if(k==1)
            {
                if(bad==1)
                    cout<<0<<endl;
                else
                    cout<<1<<endl;
            }
            else
                cout<<k-1<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define mod (int) 998244353
#define MOD (int) 1e9+7
#define X 1001100011100001111ll
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define int long long
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define in(x) scanf("%d", &x)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
#define vii vector<ii>
#define sz(s) s.size()
#define bits(n) __builtin_popcount(n)
#define mx 10000
const int MAXN = (int)((1e5) + 100);
int cuberoot(int x)
{
    int lo = 1, hi = min(2000000ll, x);
    while (hi - lo > 1)
    {
        int mid = (lo + hi) / 2;
        if (mid * mid * mid < x)
        {
            lo = mid;
        }
        else hi = mid;
    }
    if (hi * hi * hi <= x) return hi;
    else return lo;
}
const int dx[4] = { -1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int N =  (int)(1 * 1e6 + 10);
bool comp(pair<int, pair<int, int>> p1, pair<int, pair<int, int>> p2)
{
    if (p1.fi > p2.first) return true;
    else if (p1.se == p2.se)
    {
        if (p1.se.fi < p2.se.fi) return true;
    }
    return false;
}

long long  fact(long long n);

long long  ncr(long long  n,long long  r)
{
    return fact(n) / (fact(r) * fact(n - r));
}

long long  fact(long long  n)
{
    long long  res = 1;
    for (long long  i = 2; i <= n; i++)
        res = res * i;
    return res%1000000007;
}

const long long  a = 1000000000;

long long  nCr(long long  n,long long  r)
{
    long long  fac1 = 1,fac2=1,fac;
    for(long long  i=r; i>=1; i--,n--)
    {
        fac1 = fac1 * n;
        if(fac1%i==0)
            fac1 = fac1/i;
        else
            fac2 = fac2 * i;
    }
    fac = fac1/fac2;
    return fac%a;
}

int knapsack(int val[],int wt[],int W,int n)
{
    if(n==0 || W==0)
        return 0;

    if(wt[n-1]>W)
        return knapsack(val,wt,W,n-1);

    else
        return max(val[n-1]+knapsack(val,wt,W-wt[n-1],n-1),knapsack(val,wt,W,n-1));
}

const long long m=1000000007;

int tree[mx];

void build(int node,int tl,int tr,int arr[])
{
    if(tr==tl)
    {
        tree[node]=arr[tl];
        return;
    }
    int mid=(tr+tl)/2;

    build(2*node,tl,mid,arr);
    build(2*node+1,mid+1,tr,arr);

    tree[node]=tree[2*node]+tree[2*node+1];
}

int query_sum(int node,int tl,int tr,int l,int r)
{
    if(l>tr || r<tl)
        return 0;

    if(tl>=l && tr<=r)
        return tree[node];

    int mid=(tl+tr)/2;

    int p1=query_sum(2*node,tl,mid,l,r);
    int p2=query_sum(2*node+1,mid+1,tr,l,r);

    return p1+p2;
}

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

int lcm(int a, int b)
{
    return (a*b)/gcd(a, b);
}
int kadane(int arr[],int n)
{
    int  max_global,max_current;
    max_global=max_current=arr[0];

    for(int i=1; i<n; i++)
    {
        max_current=max(arr[i],arr[i]+max_global);
        ///cout<<"max_current= "<<max_current<<endl;

        if(max_current>max_global)
            max_global=max_current;
        ///cout<<"max_global= "<< max_global<<endl;
    }

    return max_global;
}
vector<ll>g[8],cost[8];
ll dist[8];
ll par[8];

ll bfs(ll src,ll dst)
{
    memset(dist,-1,sizeof(dist));
    par[src]=-1;
    dist[src]=0;
    queue<long long>q;
    q.push(src);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        if(u==dst)
            return dist[dst];

        for(auto v:g[u])
        {
            if(dist[v]==-1)
            {
                dist[v]=dist[u]+1;
                par[v]=u;
                q.push(v);
            }
        }
    }
}
void print_path(ll src,ll dst)
{
    vector<ll>path;
    ll u=dst;
    while(u!=-1)
    {
        path.push_back(u);
        u=par[u];
    }
    reverse(path.begin(),path.end());
    for(auto a:path)
        cout<<a<<" ";
    cout<<endl;
}
signed main()
{
    tc(t)
    {
        ll n;
        cin>>n;
        ll bad=0;
        ll odd=0;
        ll k=n;
        ll cnt_1=0;
        while(n--)
        {
            string s;
            cin>>s;
            if(s.length()%2==0)
                bad++;
            for(auto x:s)
            {
                if(x=='1')
                    cnt_1++;
            }
        }
        if(bad==k && cnt_1%2)
            cout<<k-1<<endl;
        else
            cout<<k<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define mod (int) 998244353
#define MOD (int) 1e9+7
#define X 1001100011100001111ll
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define int long long
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define in(x) scanf("%d", &x)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
#define vii vector<ii>
#define sz(s) s.size()
#define bits(n) __builtin_popcount(n)
#define mx 10000
const int MAXN = (int)((1e5) + 100);
int cuberoot(int x)
{
    int lo = 1, hi = min(2000000ll, x);
    while (hi - lo > 1)
    {
        int mid = (lo + hi) / 2;
        if (mid * mid * mid < x)
        {
            lo = mid;
        }
        else hi = mid;
    }
    if (hi * hi * hi <= x) return hi;
    else return lo;
}
const int dx[4] = { -1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int N =  (int)(1 * 1e6 + 10);
bool comp(pair<int, pair<int, int>> p1, pair<int, pair<int, int>> p2)
{
    if (p1.fi > p2.first) return true;
    else if (p1.se == p2.se)
    {
        if (p1.se.fi < p2.se.fi) return true;
    }
    return false;
}

long long  fact(long long n);

long long  ncr(long long  n,long long  r)
{
    return fact(n) / (fact(r) * fact(n - r));
}

long long  fact(long long  n)
{
    long long  res = 1;
    for (long long  i = 2; i <= n; i++)
        res = res * i;
    return res%1000000007;
}

const long long  a = 1000000000;

long long  nCr(long long  n,long long  r)
{
    long long  fac1 = 1,fac2=1,fac;
    for(long long  i=r; i>=1; i--,n--)
    {
        fac1 = fac1 * n;
        if(fac1%i==0)
            fac1 = fac1/i;
        else
            fac2 = fac2 * i;
    }
    fac = fac1/fac2;
    return fac%a;
}

int knapsack(int val[],int wt[],int W,int n)
{
    if(n==0 || W==0)
        return 0;

    if(wt[n-1]>W)
        return knapsack(val,wt,W,n-1);

    else
        return max(val[n-1]+knapsack(val,wt,W-wt[n-1],n-1),knapsack(val,wt,W,n-1));
}

const long long m=1000000007;

int tree[mx];

void build(int node,int tl,int tr,int arr[])
{
    if(tr==tl)
    {
        tree[node]=arr[tl];
        return;
    }
    int mid=(tr+tl)/2;

    build(2*node,tl,mid,arr);
    build(2*node+1,mid+1,tr,arr);

    tree[node]=tree[2*node]+tree[2*node+1];
}

int query_sum(int node,int tl,int tr,int l,int r)
{
    if(l>tr || r<tl)
        return 0;

    if(tl>=l && tr<=r)
        return tree[node];

    int mid=(tl+tr)/2;

    int p1=query_sum(2*node,tl,mid,l,r);
    int p2=query_sum(2*node+1,mid+1,tr,l,r);

    return p1+p2;
}

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

int lcm(int a, int b)
{
    return (a*b)/gcd(a, b);
}
int kadane(int arr[],int n)
{
    int  max_global,max_current;
    max_global=max_current=arr[0];

    for(int i=1; i<n; i++)
    {
        max_current=max(arr[i],arr[i]+max_global);
        ///cout<<"max_current= "<<max_current<<endl;

        if(max_current>max_global)
            max_global=max_current;
        ///cout<<"max_global= "<< max_global<<endl;
    }

    return max_global;
}
vector<ll>g[8],cost[8];
ll dist[8];
ll par[8];

ll bfs(ll src,ll dst)
{
    memset(dist,-1,sizeof(dist));
    par[src]=-1;
    dist[src]=0;
    queue<long long>q;
    q.push(src);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        if(u==dst)
            return dist[dst];

        for(auto v:g[u])
        {
            if(dist[v]==-1)
            {
                dist[v]=dist[u]+1;
                par[v]=u;
                q.push(v);
            }
        }
    }
}
void print_path(ll src,ll dst)
{
    vector<ll>path;
    ll u=dst;
    while(u!=-1)
    {
        path.push_back(u);
        u=par[u];
    }
    reverse(path.begin(),path.end());
    for(auto a:path)
        cout<<a<<" ";
    cout<<endl;
}
signed main()
{
    tc(t)
    {
         ll n;
         cin>>n;
         ll bad=0;
         ll odd=0;
         ll k=n;
         while(n--){
            string s;
            cin>>s;
            if(s.length()%2==0)
                bad++;
            else
                odd++;
         }
         if(bad%2==1 && odd>=1){
            cout<<k<<endl;
         }
         else
            cout<<k-1<<endl;
    }
}


#include<iostream>
#include<bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
using namespace std;
int main()
{
	ll t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vector<string> a(n);
		ll diff=0;
		ll od =0;

		for(int i=0;i<n;i++)
		{
			cin>>a[i];
			if(a[i].length()%2==1)
			{
			//	cout<<"ODD length string"<<endl;
				od++;
			}
			for(int j=0;j<a[i].length()/2;j++)
			{
				if(a[i][j]!=a[i][a[i].length()-j-1])
				{
					diff++;
				}
			}
		}
		if(diff&1&&(od==0))
		{
			cout<<n-1<<endl;
		}
		else
		{
			cout<<n<<endl;
		}
	}

}


#include<iostream>
#include<bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
using namespace std;
int main()
{
	ll t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vector<string> a(n);
		ll diff=0;
		ll od =0;

		for(int i=0;i<n;i++)
		{
			cin>>a[i];
			if(a[i].length()%2==1)
			{
			//	cout<<"ODD length string"<<endl;
				od++;
			}
			for(int j=0;j<a[i].length()/2;j++)
			{
				if(a[i][j]!=a[i][a[i].length()-j+1])
				{
					diff++;
				}
			}
		}
		if(diff&1&&(od==0))
		{
			cout<<n-1<<endl;
		}
		else
		{
			cout<<n<<endl;
		}
	}

}


#include<iostream>
#include<bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
using namespace std;
int main()
{
	ll t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vector<string> a(n);
		ll diff=0;
		ll od =0;

		for(int i=0;i<n;i++)
		{
			cin>>a[i];
			if(a[i].length()%2==1)
			{
			//	cout<<"ODD length string"<<endl;
				od++;
			}
			for(int j=0;j<a[i].length()/2;j++)
			{
				if(a[i][j]!=a[i][a[i].length()-j+1])
				{
					diff++;
				}
			}
		}
		if(diff%2==0&&od==0)
		{
			cout<<n-1<<endl;
		}
		else
		{
			cout<<n<<endl;
		}
	}

}


#include<iostream>
#include<bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
using namespace std;
int main()
{
	ll t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vector<string> a(n);
		ll diff=0;
		ll od =0;

		for(int i=0;i<n;i++)
		{
			cin>>a[i];
			if(a[i].length()%2==1)
			{
			//	cout<<"ODD length string"<<endl;
				od++;
			}
			for(int j=0;j<a[i].length()/2;j++)
			{
				if(a[i][j]!=a[i][a[i].length()-j+1])
				{
					diff++;
				}
			}
		}
		if(diff%2==1&&od==0)
		{
			cout<<n-1<<endl;
		}
		else
		{
			cout<<n<<endl;
		}
	}

}


#include <bits/stdc++.h>
using namespace std;
#define mu  1000000007
#define ll  long long int
#define vec vector< long long int>
#define pb  push_back
#define mk  make_pair
#define forn(a,b) for(int a=0;a<b;a++)
#define MAX 100001
#define INF INT_MAX
#define yes cout<<"YES\n"
#define no  cout <<"NO\n"
#define ull unsigned long long int
#define all(x) begin(x),end(x)
ll gcd(ll a, ll b){
        if (a == 0)
            return b;
        return gcd(b%a, a);
    }
bool cmp(const pair<int,int > &a,const pair<int,int> &b)
{
    if(a.first==b.first)
        return a.second<b.second;
    return a.first<b.first;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		vector<string > s;
		cin>>n;
		s.resize(n);
		int total=0,ans=0;
		forn(i,n)
		{
			string g;
			cin>>g;
			int ones=0,zeros=0;
			for(int j=0;j<g.size();j++)
			{
				if(g[j]=='0')
					zeros++;
				else
					ones++;
			}
			if(zeros%2==1&&ones%2==1)
			{
				total++;
			}
			else
				ans++;
		}
		if(ans)
			cout<<n<<endl;
		else
			cout<<ans+total-1<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mu  1000000007
#define ll  long long int
#define vec vector< long long int>
#define pb  push_back
#define mk  make_pair
#define forn(a,b) for(int a=0;a<b;a++)
#define MAX 100001
#define INF INT_MAX
#define yes cout<<"YES\n"
#define no  cout <<"NO\n"
#define ull unsigned long long int
#define all(x) begin(x),end(x)
ll gcd(ll a, ll b){
        if (a == 0)
            return b;
        return gcd(b%a, a);
    }
bool cmp(const pair<int,int > &a,const pair<int,int> &b)
{
    if(a.first==b.first)
        return a.second<b.second;
    return a.first<b.first;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		vector<string > s;
		cin>>n;
		s.resize(n);
		int odd=0,bad=0;
		forn(i,n)
		{
			string g;
			cin>>g;
			int one=0,zero=0;
			if(g.size()%2==1)
				odd++;
			else
			{
				forn(j,g.size())
				if(g[j]=='0')
					zero++;
				else
					one++;
				if(one%2==1&&zero%2==1)
				{
					bad++;
				}
			}
		}
		if(odd==0&&bad%2==1)
			cout<<n-1<<endl;
		else
			cout<<n<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mu  1000000007
#define ll  long long int
#define vec vector< long long int>
#define pb  push_back
#define mk  make_pair
#define forn(a,b) for(int a=0;a<b;a++)
#define MAX 100001
#define INF INT_MAX
#define yes cout<<"YES\n"
#define no  cout <<"NO\n"
#define ull unsigned long long int
#define all(x) begin(x),end(x)
ll gcd(ll a, ll b){
        if (a == 0)
            return b;
        return gcd(b%a, a);
    }
bool cmp(const pair<int,int > &a,const pair<int,int> &b)
{
    if(a.first==b.first)
        return a.second<b.second;
    return a.first<b.first;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		vector<string > s;
		cin>>n;
		s.resize(n);
		int total=0,ans=0;
		forn(i,n)
		{
			string g;
			cin>>g;
			int ones=0,zeros=0;
			for(int j=0;j<g.size();j++)
			{
				if(g[j]=='0')
					zeros++;
				else
					ones++;
			}
			if(zeros%2==1&&ones%2==1)
			{
				total++;
			}
			else
				ans++;
		}
		if(ans)
			cout<<n<<endl;
		else
			cout<<ans+total-1;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mu  1000000007
#define ll  long long int
#define vec vector< long long int>
#define pb  push_back
#define mk  make_pair
#define forn(a,b) for(int a=0;a<b;a++)
#define MAX 100001
#define INF INT_MAX
#define yes cout<<"YES\n"
#define no  cout <<"NO\n"
#define ull unsigned long long int
#define all(x) begin(x),end(x)
ll gcd(ll a, ll b){
        if (a == 0)
            return b;
        return gcd(b%a, a);
    }
bool cmp(const pair<int,int > &a,const pair<int,int> &b)
{
    if(a.first==b.first)
        return a.second<b.second;
    return a.first<b.first;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		vector<string > s;
		cin>>n;
		s.resize(n);
		int total=0,ans=0;
		forn(i,n)
		{
			string g;
			cin>>g;
			int ones=0,zeros=0;
			for(int j=0;j<g.size();j++)
			{
				if(g[j]=='0')
					zeros++;
				else
					ones++;
			}
			if(zeros%2==1&&ones%2==1)
			{
				total++;
			}
			else
				ans++;
		}
		if(ans)
			cout<<n<<endl;
		else
			if(total%2==0)
				cout<<n<<endl;
			else
				cout<<n-1<<endl;
	}
	return 0;
}


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

char k[51][51];
int main()
{
    int n;
    cin >>n;
    while(n--){
        int t;
        cin >> t;
        memset(k,0,sizeof k);
        for(int i = 0; i < t; i++){
            cin >> k[i];
        }
        int sum1 = 0;
        int sum2 = 0;
        int flag = 1;
        for(int i = 0; i < t; i++){
            int len = strlen(k[i]);
            if(len&1)  flag^=1;
            for(int j = 0; j < len; j++){
                if(k[i][j]=='0')  sum1++;
                else sum2++;
            }
        }
      if(flag||sum2%2==0||sum1%2==0)  cout <<t <<endl;
      else {
        cout << t-1 <<endl;
      }
    }
}


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

char k[51][51];
int main()
{
    int n;
    cin >>n;
    while(n--){
        int t;
        cin >> t;
        memset(k,0,sizeof k);
        for(int i = 0; i < t; i++){
            cin >> k[i];
        }
        int sum1 = 0;
        int flag = 0;
        for(int i = 0; i < t; i++){
            int len = strlen(k[i]);
            if(len&1)  flag = 1;
            for(int j = 0; j < len; j++){
                if(k[i][j]=='0')  sum1++;
            }
        }
      if(flag||sum1%2==0)  cout <<t <<endl;
      else {
        cout << t-1 <<endl;
      }
    }
}


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

char k[51][51];
int main()
{
    int n;
    cin >>n;
    while(n--){
        int t;
        cin >> t;
        memset(k,0,sizeof k);
        for(int i = 0; i < t; i++){
            cin >> k[i];
        }
        int sum1 = 0;
        int sum2 = 0;
        int flag = 1;
        for(int i = 0; i < t; i++){
            int len = strlen(k[i]);
            if(len&1)  flag^=1;
            for(int j = 0; j < len; j++){
                if(k[i][j]=='0')  sum1++;
                else sum2++;
            }
        }
      if(!flag||sum2%2==0)  cout <<t <<endl;
      else {
        cout << t-1 <<endl;
      }
    }
}


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

char k[51][51];
int main()
{
    int n;
    cin >>n;
    while(n--){
        int t;
        cin >> t;
        memset(k,0,sizeof k);
        for(int i = 0; i < t; i++){
            cin >> k[i];
        }
        int sum1 = 0;
        int sum2 = 0;
        int flag = 1;
        for(int i = 0; i < t; i++){
            int len = strlen(k[i]);
            if(len&1)  flag^=0;
            for(int j = 0; j < len; j++){
                if(k[i][j]=='0')  sum1++;
                else sum2++;
            }
        }
       if(flag==1){
        if((sum1&1&&sum2%2==0)||(sum1%2==0&&sum2&1)) ;
        else t--;
       }
       else{
        if(sum1&1||sum2&1) t--;
       }
        cout << t <<endl;
    }
}


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

char k[51][51];
int main()
{
    int n;
    cin >>n;
    while(n--){
        int t;
        cin >> t;
        memset(k,0,sizeof k);
        for(int i = 0; i < t; i++){
            cin >> k[i];
        }
        int sum1 = 0;
        int sum2 = 0;
        int flag = 1;
        for(int i = 0; i < t; i++){
            int len = strlen(k[i]);
            if(len&1)  flag^=1;
            for(int j = 0; j < len; j++){
                if(k[i][j]=='0')  sum1++;
                else sum2++;
            }
        }
      if(!flag||sum2%2==0||sum1%2==0)  cout <<t <<endl;
      else {
        cout << t-1 <<endl;
      }
    }
}


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

char k[51][51];
int main()
{
    int n;
    cin >>n;
    while(n--){
        int t;
        cin >> t;
        memset(k,0,sizeof k);
        for(int i = 0; i < t; i++){
            cin >> k[i];
        }
        int sum1 = 0;
        int sum2 = 0;
        int flag = 1;
        for(int i = 0; i < t; i++){
            int len = strlen(k[i]);
            if(len&1)  flag^=0;
            for(int j = 0; j < len; j++){
                if(k[i][j]=='0')  sum1++;
                else sum2++;
            }
        }
      if(sum1&1||sum2&1){
        if(!flag)  t--;
      }
      cout << t <<endl;
    }
}


#include<bits/stdc++.h>

using namespace std;

bool ok ( string s1 ,string s2){
if(s1.length()%2==0&&s2.length()%2==0)return true;
return s1.length()>s2.length();
}

int main()
{
    //ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    /// scanf("%I64d",&x);
    /// printf("%I64d",&x);
    /// printf("%d",&n);
    /// printf(st);
    /// for(int i=0;i<m ;i++){ }
    //    scanf("%d",&t);
    long long n,k,e=0,o=0,cnt=0,sum=0,ans=0,t;

    cin>>t;

 while(t--){
    cin>>n;
    o=cnt=0;
    string ss;
    vector<string>st;
    for(int i=0;i<n;i++){
        cin>>ss;
        st.push_back(ss);
    int j=0;
        for(j=0;st[i][j]!='\0';j++)
        if(st[i][j]=='1')o++;
        if(j%2!=0)cnt++;
    }
    sort(st.begin(),st.end(),ok);
    for(int i=0;i<n;i++){
            int si=st[i].length();
      if(!o);
      else if(o>=si)o-=si;
      else if(o%2==0)o=0;
      else if(si%2==1)o=0;
      else if(si%2==0) o%=2;
    }
if(n==1){
    if(o%2==1&&cnt==0)
        cout<<0<<endl;
    else
        cout<<1<<endl;
}
else if(!o)
    cout<<n<<endl;
else
    cout<<n-1<<endl;
}

return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    //ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    /// scanf("%I64d",&x);
    /// printf("%I64d",&x);
    /// printf("%d",&n);
    /// printf(st);
    /// for(int i=0;i<m ;i++){ }
    //    scanf("%d",&t);
    long long n,k,e=0,o=0,cnt=0,sum=0,ans=0,t;

    cin>>t;

 while(t--){
    cin>>n;
    o=cnt=0;
    string ss;
    vector<string>oddst;
    vector<string>evvst;
    for(int i=0;i<n;i++){
        cin>>ss;
        if(ss.length()%2==0)
        evvst.push_back(ss);
        else
        oddst.push_back(ss);
        for(int j=0;ss[j]!='\0';j++)
        if(ss[j]=='1')o++;
    }
    sort(oddst.rbegin(),oddst.rend());
    sort(evvst.rbegin(),evvst.rend());
    for(int i=0;i<evvst.size();i++){
            int si=evvst[i].length();
      if(!o);
      else if(o>=si)o-=si;
      else if(o%2==0)o=0;
      else  o%=2;
    }
    for(int i=0;i<oddst.size();i++){
            int si=oddst[i].length();
      if(!o);
      else if(o>=si)o-=si;
      else o=0;
    }

if(!o)
    cout<<n<<endl;
else
    cout<<n-1<<endl;
}

return 0;
}


#include<bits/stdc++.h>

using namespace std;

bool ok ( string s1 ,string s2){
if(s1.length()%2==0&&s2.length()%2==0)return true;
return s1.length()>s2.length();
}

int main()
{
    //ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    /// scanf("%I64d",&x);
    /// printf("%I64d",&x);
    /// printf("%d",&n);
    /// printf(st);
    /// for(int i=0;i<m ;i++){ }
    //    scanf("%d",&t);
    long long n,k,e=0,o=0,cnt=0,sum=0,ans=0,t;

    cin>>t;

 while(t--){
    cin>>n;
    o=cnt=0;
    string ss;
    vector<string>st;
    for(int i=0;i<n;i++){
        cin>>ss;
        st.push_back(ss);
    int j=0;
        for(j=0;st[i][j]!='\0';j++)
        if(st[i][j]=='1')o++;
        if(j%2!=0)cnt++;
    }
    sort(st.begin(),st.end(),ok);
    for(int i=0;i<n;i++){
            int si=st[i].length();
      if(!o);
      else if(o>=si)o-=si;
      else if(o%2==0)o=0;
      else if(o%2==1 && si%2==1)o=0;
      else if (o) o=1;
    }
if(n==1){
    if(o%2==1&&cnt==0)
        cout<<0<<endl;
    else
        cout<<1<<endl;
}
else if(!o)
    cout<<n<<endl;
else
    cout<<n-1<<endl;
}

return 0;
}


#include<bits/stdc++.h>

using namespace std;

bool ok ( string s1 ,string s2){
if(s1.length()%2==0&&s2.length()%2==0)return true;
return s1.length()>s2.length();
}

int main()
{
    //ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    /// scanf("%I64d",&x);
    /// printf("%I64d",&x);
    /// printf("%d",&n);
    /// printf(st);
    /// for(int i=0;i<m ;i++){ }
    //    scanf("%d",&t);
    long long n,k,e=0,o=0,cnt=0,sum=0,ans=0,t;

    cin>>t;

 while(t--){
    cin>>n;
    o=cnt=0;
    string ss;
    vector<string>st;
    for(int i=0;i<n;i++){
        cin>>ss;
        st.push_back(ss);
    int j=0;
        for(j=0;st[i][j]!='\0';j++)
        if(st[i][j]=='1')o++;
        if(j%2!=0)cnt++;
    }
    sort(st.begin(),st.end(),ok);
    for(int i=0;i<n;i++){
            int si=st[i].length();
      if(o>si)o-=si;
      else if(o%2==1 && si%2==1)o-=1;
      else if(o%2==0 && si%2==0)o=0;
      else if(si%2==0)o=1;
    }
if(n==1){
    if(o%2==1&&cnt==0)
        cout<<0<<endl;
    else
        cout<<1<<endl;
}
else if(!o)
    cout<<n<<endl;
else
    cout<<n-1<<endl;
}

return 0;
}


#include<bits/stdc++.h>

using namespace std;

bool ok ( string s1 ,string s2){
if(s1.length()%2==0&&s2.length()%2==0)return true;
return s1.length()>s2.length();
}

int main()
{
    //ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    /// scanf("%I64d",&x);
    /// printf("%I64d",&x);
    /// printf("%d",&n);
    /// printf(st);
    /// for(int i=0;i<m ;i++){ }
    //    scanf("%d",&t);
    long long n,k,e=0,o=0,cnt=0,sum=0,ans=0,t;

    cin>>t;

 while(t--){
    cin>>n;
    o=cnt=0;
    string ss;
    vector<string>st;
    for(int i=0;i<n;i++){
        cin>>ss;
        st.push_back(ss);
    int j=0;
        for(j=0;st[i][j]!='\0';j++)
        if(st[i][j]=='1')o++;
        if(j%2!=0)cnt++;
    }
    sort(st.begin(),st.end(),ok);
    for(int i=0;i<n;i++){
            int si=st[i].length();
      if(o>si)o-=si;
      else if(o%2==1 && si%2==1)o-=1;
      else if(o%2==0 && si%2==0)o=0;
      else if(si%2==0)o=1;
    }

if(!o)
    cout<<n<<endl;
else
    cout<<n-1<<endl;
}

return 0;
}


#include<bits/stdc++.h>

using namespace std;

bool ok ( string s1 ,string s2){
if(s1.length()%2==0&&s2.length()%2==0)return true;
return s1.length()>s2.length();
}

int main()
{
    //ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    /// scanf("%I64d",&x);
    /// printf("%I64d",&x);
    /// printf("%d",&n);
    /// printf(st);
    /// for(int i=0;i<m ;i++){ }
    //    scanf("%d",&t);
    long long n,k,e=0,o=0,cnt=0,sum=0,ans=0,t;

    cin>>t;

 while(t--){
    cin>>n;
    o=cnt=0;
    string ss;
    vector<string>st;
    for(int i=0;i<n;i++){
        cin>>ss;
        st.push_back(ss);
    int j=0;
        for(j=0;st[i][j]!='\0';j++)
        if(st[i][j]=='1')o++;
        if(j%2!=0)cnt++;
    }
    sort(st.begin(),st.end(),ok);
    for(int i=0;i<n;i++){
            int si=st[i].length();
      if(o>si)o-=si;
      else if(o%2==0||si==1)o=0;
      else if(o%2==1 && si%2==1)o=0;
      else if (o) o=1;
    }
if(n==1){
    if(o%2==1&&cnt==0)
        cout<<0<<endl;
    else
        cout<<1<<endl;
}
else if(!o)
    cout<<n<<endl;
else
    cout<<n-1<<endl;
}

return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    /// scanf("%I64d",&x);
    /// printf("%I64d",&x);
    /// printf("%d",&n);
    /// printf(st);
    /// for(int i=0;i<m ;i++){ }
    //    scanf("%d",&t);
    long long n,k,e=0,o=0,cnt=0,sum=0,ans=0,t;

    cin>>t;

 while(t--){
    cin>>n;
    o=cnt=0;
    string ss;
    vector<string>st;
    for(int i=0;i<n;i++){
        cin>>ss;
        st.push_back(ss);
    int j=0;
        for(j=0;st[i][j]!='\0';j++)
        if(st[i][j]=='1')o++;
        if(j%2!=0)cnt++;
    }
    ans=n;
    if(o%2!=0 && cnt%2==0 ){
       ans=n-1;
    }

cout<<ans<<endl;

}

return 0;
}


#include<bits/stdc++.h>

using namespace std;

bool ok ( string s1 ,string s2){
if(s1.length()%2==0&&s2.length()%2==0)return true;
return s1.length()>s2.length();
}

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    /// scanf("%I64d",&x);
    /// printf("%I64d",&x);
    /// printf("%d",&n);
    /// printf(st);
    /// for(int i=0;i<m ;i++){ }
    //    scanf("%d",&t);
    long long n,k,e=0,o=0,cnt=0,sum=0,ans=0,t;

    cin>>t;

 while(t--){
    cin>>n;
    o=cnt=0;
    string ss;
    vector<string>st;
    for(int i=0;i<n;i++){
        cin>>ss;
        st.push_back(ss);
    int j=0;
        for(j=0;st[i][j]!='\0';j++)
        if(st[i][j]=='1')o++;
        if(j%2!=0)cnt++;
    }

if(o%2==1&&cnt%2==0&&n!=1)
    cout<<n-1<<endl;
else
    cout<<n<<endl;
}

return 0;
}


#include<bits/stdc++.h>

using namespace std;

bool ok ( string s1 ,string s2){
if(s1.length()%2==0&&s2.length()%2==0)return true;
return s1.length()>s2.length();
}

int main()
{
    //ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    /// scanf("%I64d",&x);
    /// printf("%I64d",&x);
    /// printf("%d",&n);
    /// printf(st);
    /// for(int i=0;i<m ;i++){ }
    //    scanf("%d",&t);
    long long n,k,e=0,o=0,cnt=0,sum=0,ans=0,t;

    cin>>t;

 while(t--){
    cin>>n;
    o=cnt=0;
    string ss;
    vector<string>st;
    for(int i=0;i<n;i++){
        cin>>ss;
        st.push_back(ss);
    int j=0;
        for(j=0;st[i][j]!='\0';j++)
        if(st[i][j]=='1')o++;
        if(j%2!=0)cnt++;
    }
    sort(st.begin(),st.end(),ok);
    for(int i=0;i<n;i++){
            int si=st[i].length();
      if(o>si)o-=si;
      else if(o%2==1 && si%2==1)o=0;
      else if(o%2==0)o=0;
      else if(si%2==0)o=1;
    }
if(n==1){
    if(o%2==1&&cnt==0)
        cout<<0<<endl;
    else
        cout<<1<<endl;
}
else if(!o)
    cout<<n<<endl;
else
    cout<<n-1<<endl;
}

return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    /// scanf("%I64d",&x);
    /// printf("%I64d",&x);
    /// printf("%d",&n);
    /// printf(st);
    /// for(int i=0;i<m ;i++){ }
    //    scanf("%d",&t);
    long long n,k,e=0,o=0,cnt=0,sum=0,ans=0,t;

    cin>>t;

 while(t--){
     set<char>se;
        string st;
    cin>>st;
for(int i=0;st[i];i++)se.insert( st[i]);
while(!se.empty()){
char c=*se.begin();
se.erase(c);
for(int i=0;st[i];i++){
    if(st[i]==c)
    {
        if(i-1>-1){
           if(st[i-1]==c)
            continue;
           }
           if(i+1<st.length()){
            if(st[i+1]==c)
            continue;
           }
   cout<<c;
    break;
    }

}

}
cout<<endl;
}

return 0;
}


#include<bits/stdc++.h>

using namespace std;

bool ok ( string s1 ,string s2){
if(s1.length()%2==0&&s2.length()%2==0)return true;
return s1.length()>s2.length();
}

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    /// scanf("%I64d",&x);
    /// printf("%I64d",&x);
    /// printf("%d",&n);
    /// printf(st);
    /// for(int i=0;i<m ;i++){ }
    //    scanf("%d",&t);
    long long n,k,e=0,o=0,cnt=0,sum=0,ans=0,t;

    cin>>t;

 while(t--){
    cin>>n;
    o=cnt=0;
    string ss;
    vector<string>st;
    for(int i=0;i<n;i++){
        cin>>ss;
        st.push_back(ss);
    int j=0;
        for(j=0;st[i][j]!='\0';j++)
        if(st[i][j]=='1')o++;
        if(j%2!=0)cnt++;
    }

if(n==1){
 if(cnt==0&&o%2==1)
    cout<<0<<endl;
else
    cout<<1<<endl;
}else if(o%2==1&&cnt%2==0)
    cout<<n-1<<endl;
else
    cout<<n<<endl;
}

return 0;
}


#include<bits/stdc++.h>

using namespace std;

bool ok ( string s1 ,string s2){
if(s1.length()%2==0&&s2.length()%2==0)return true;
return s1.length()>s2.length();
}

int main()
{
    //ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    /// scanf("%I64d",&x);
    /// printf("%I64d",&x);
    /// printf("%d",&n);
    /// printf(st);
    /// for(int i=0;i<m ;i++){ }
    //    scanf("%d",&t);
    long long n,k,e=0,o=0,cnt=0,sum=0,ans=0,t;

    cin>>t;

 while(t--){
    cin>>n;
    o=cnt=0;
    string ss;
    vector<string>st;
    for(int i=0;i<n;i++){
        cin>>ss;
        st.push_back(ss);
    int j=0;
        for(j=0;st[i][j]!='\0';j++)
        if(st[i][j]=='1')o++;
        if(j%2!=0)cnt++;
    }
    sort(st.begin(),st.end(),ok);
    for(int i=0;i<n;i++){
            int si=st[i].length();
      if(o>si)o-=si;
      else if (si==1&&o)o--;
      else if(o%2==0)o=0;
      else if(o%2==1 && si%2==1)o=0;
      else if (o) o=1;
    }
if(n==1){
    if(o%2==1&&cnt==0)
        cout<<0<<endl;
    else
        cout<<1<<endl;
}
else if(!o)
    cout<<n<<endl;
else
    cout<<n-1<<endl;
}

return 0;
}


#include<bits/stdc++.h>

using namespace std;

bool ok ( string s1 ,string s2){
if(s1.length()%2==0&&s2.length()%2==0)return true;
return s1.length()>s2.length();
}

int main()
{
    //ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    /// scanf("%I64d",&x);
    /// printf("%I64d",&x);
    /// printf("%d",&n);
    /// printf(st);
    /// for(int i=0;i<m ;i++){ }
    //    scanf("%d",&t);
    long long n,k,e=0,o=0,cnt=0,sum=0,ans=0,t;

    cin>>t;

 while(t--){
    cin>>n;
    o=cnt=0;
    string ss;
    vector<string>st;
    for(int i=0;i<n;i++){
        cin>>ss;
        st.push_back(ss);
    int j=0;
        for(j=0;st[i][j]!='\0';j++)
        if(st[i][j]=='1')o++;
        if(j%2!=0)cnt++;
    }
    sort(st.begin(),st.end(),ok);
    for(int i=0;i<n;i++){
            int si=st[i].length();
      if(o>=si)o-=si;
      else if(o%2==0)o=0;
      else if(o%2==1 && si%2==1)o=0;
      else if (o) o=1;
    }
if(n==1){
    if(o%2==1&&cnt==0)
        cout<<0<<endl;
    else
        cout<<1<<endl;
}
else if(!o)
    cout<<n<<endl;
else
    cout<<n-1<<endl;
}

return 0;
}


#include<bits/stdc++.h>

using namespace std;

bool ok ( string s1 ,string s2){
if(s1.length()%2==0&&s2.length()%2==0)return true;
return s1.length()>s2.length();
}

int main()
{
    //ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    /// scanf("%I64d",&x);
    /// printf("%I64d",&x);
    /// printf("%d",&n);
    /// printf(st);
    /// for(int i=0;i<m ;i++){ }
    //    scanf("%d",&t);
    long long n,k,e=0,o=0,cnt=0,sum=0,ans=0,t;

    cin>>t;

 while(t--){
    cin>>n;
    o=cnt=0;
    string ss;
    vector<string>st;
    for(int i=0;i<n;i++){
        cin>>ss;
        st.push_back(ss);
    int j=0;
        for(j=0;st[i][j]!='\0';j++)
        if(st[i][j]=='1')o++;
        if(j%2!=0)cnt++;
    }
    sort(st.begin(),st.end(),ok);
    for(int i=0;i<n;i++){
            int si=st[i].length();
      if(o>si)o-=si;
      else if (si==1)o--;
      else if(o%2==0)o=0;
      else if(o%2==1 && si%2==1)o=0;
      else if (o) o=1;
    }
if(n==1){
    if(o%2==1&&cnt==0)
        cout<<0<<endl;
    else
        cout<<1<<endl;
}
else if(!o)
    cout<<n<<endl;
else
    cout<<n-1<<endl;
}

return 0;
}


#include<bits/stdc++.h>

using namespace std;

bool ok ( string s1 ,string s2){
if(s1.length()%2==0&&s2.length()%2==0)return true;
return s1.length()>s2.length();
}

int main()
{
    //ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    /// scanf("%I64d",&x);
    /// printf("%I64d",&x);
    /// printf("%d",&n);
    /// printf(st);
    /// for(int i=0;i<m ;i++){ }
    //    scanf("%d",&t);
    long long n,k,e=0,o=0,cnt=0,sum=0,ans=0,t;

    cin>>t;

 while(t--){
    cin>>n;
    o=cnt=0;
    string ss;
    vector<string>st;
    for(int i=0;i<n;i++){
        cin>>ss;
        st.push_back(ss);
    int j=0;
        for(j=0;st[i][j]!='\0';j++)
        if(st[i][j]=='1')o++;
        if(j%2!=0)cnt++;
    }
    sort(st.begin(),st.end(),ok);
    for(int i=0;i<n;i++){
            int si=st[i].length();
      if(o>si)o-=si;
      else if(o%2==1 && si%2==1)o-=1;
      else if(o%2==0 && si%2==0)o=0;
      else if(o%2==1&&si%2==0)o=1;
    }

if(!o)
    cout<<n<<endl;
else
    cout<<n-1<<endl;
}

return 0;
}


#include<bits/stdc++.h>

using namespace std;

bool ok ( string s1 ,string s2){
if(s1.length()%2==0&&s2.length()%2==0)return true;
return s1.length()>s2.length();
}

int main()
{
    //ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    /// scanf("%I64d",&x);
    /// printf("%I64d",&x);
    /// printf("%d",&n);
    /// printf(st);
    /// for(int i=0;i<m ;i++){ }
    //    scanf("%d",&t);
    long long n,k,e=0,o=0,cnt=0,sum=0,ans=0,t;

    cin>>t;

 while(t--){
    cin>>n;
    o=cnt=0;
    string ss;
    vector<string>st;
    for(int i=0;i<n;i++){
        cin>>ss;
        st.push_back(ss);
    int j=0;
        for(j=0;st[i][j]!='\0';j++)
        if(st[i][j]=='1')o++;
        if(j%2!=0)cnt++;
    }
    sort(st.begin(),st.end(),ok);
    for(int i=0;i<n;i++){
            int si=st[i].length();
      if(o>si)o-=si;
      else if(o%2==0)o=0;
      else if(o&&o%2==1 && si%2==1)o=0;
      else if (o) o=1;
    }
if(n==1){
    if(o%2==1&&cnt==0)
        cout<<0<<endl;
    else
        cout<<1<<endl;
}
else if(!o)
    cout<<n<<endl;
else
    cout<<n-1<<endl;
}

return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b){return (1ll*a*b)/gcd(a, b);}
int zero,one;
bool cmp(string a,string b)
{
    return a.size() < b.size();
}
bool can(string s)
{
    int temp = one, temp2 = zero;
    for(int i=0;i<s.size();++i)
    {
        if(s[i]!=s[s.size()-i-1])
        {
            if(s[i]=='1')
            {
                if(one)
                {
                    temp-=2;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                if(s[i]=='0')
                {
                    if(zero)
                    {
                        temp2-=2;
                    }
                    else return false;
                }
            }
        }
        else
        {
            if(i==s.size()-i-1)
            {
                if(s[i]=='1')
                {
                    if(temp) temp--;
                    else return false;
                }
                else
                {
                    if(temp2) temp2--;
                    else return false;
                }
            }
            else
            {
                if(s[i]=='1') temp-=2; else temp2-=2;
            }
        }
    }
    one = temp, zero = temp2;
    return true;
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t; cin>>t;
    while(t--)
    {
        int n; cin>>n;
        vector<string> a(n); zero = 0, one = 0;
        for(int i=0;i<n;++i) {cin>>a[i]; for(auto l : a[i]) if(l=='1') one++; else zero++;}
        sort(a.begin(),a.end(),cmp); int ans = 0; int odd=0;
        for(int i=0;i<a.size();++i)
        {
            if(a[i].size()&1) odd++;
        }
        if(!(one&1) || !(zero&1)) cout<<n<<'\n';
        else if(odd>0)
        {
            cout<<n<<'\n';
        }
        else cout<<n-1<<'\n';
    }
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b){return (1ll*a*b)/gcd(a, b);}
int zero,one;
bool cmp(string a,string b)
{
    return a.size() < b.size();
}
bool can(string s)
{
    int temp = one, temp2 = zero;
    for(int i=0;i<s.size();++i)
    {
        if(s[i]!=s[s.size()-i-1])
        {
            if(s[i]=='1')
            {
                if(one)
                {
                    temp-=2;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                if(s[i]=='0')
                {
                    if(zero)
                    {
                        temp2-=2;
                    }
                    else return false;
                }
            }
        }
        else
        {
            if(i==s.size()-i-1)
            {
                if(s[i]=='1')
                {
                    if(temp) temp--;
                    else return false;
                }
                else
                {
                    if(temp2) temp2--;
                    else return false;
                }
            }
            else
            {
                if(s[i]=='1') temp-=2; else temp2-=2;
            }
        }
    }
    one = temp, zero = temp2;
    return true;
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t; cin>>t;
    while(t--)
    {
        int n; cin>>n;
        vector<string> a(n); zero = 0, one = 0;
        for(int i=0;i<n;++i) {cin>>a[i]; for(auto l : a[i]) if(l=='1') one++; else zero++;}
        sort(a.begin(),a.end(),cmp); int ans = 0; int odd=0;
        for(int i=0;i<a.size();++i)
        {
            if(a[i].size()&1) odd++;
        }
        if(!one&1 || !zero&1) cout<<n<<'\n';
        else if(odd>0)
        {
            cout<<n<<'\n';
        }
        else cout<<n-1<<'\n';
    }
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b){return (1ll*a*b)/gcd(a, b);}
int zero,one;
bool cmp(string a,string b)
{
    return a.size() < b.size();
}
bool can(string s)
{
    int temp = one, temp2 = zero;
    for(int i=0;i<s.size();++i)
    {
        if(s[i]!=s[s.size()-i-1])
        {
            if(s[i]=='1')
            {
                if(one)
                {
                    temp-=2;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                if(s[i]=='0')
                {
                    if(zero)
                    {
                        temp2-=2;
                    }
                    else return false;
                }
            }
        }
        else
        {
            if(i==s.size()-i-1)
            {
                if(s[i]=='1')
                {
                    if(temp) temp--;
                    else return false;
                }
                else
                {
                    if(temp2) temp2--;
                    else return false;
                }
            }
            else
            {
                if(s[i]=='1') temp-=2; else temp2-=2;
            }
        }
    }
    one = temp, zero = temp2;
    return true;
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t; cin>>t;
    while(t--)
    {
        int n; cin>>n;
        vector<string> a(n); zero = 0, one = 0;
        for(int i=0;i<n;++i) {cin>>a[i]; for(auto l : a[i]) if(l=='1') one++; else zero++;}
        sort(a.begin(),a.end(),cmp); int ans = 0; int odd=0;
        for(int i=0;i<a.size();++i)
        {
            if(a[i].size()&1) odd++;
        }
        if(odd>0)
        {
            cout<<n<<'\n';
        }
        else cout<<n-1<<'\n';
    }
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b){return (1ll*a*b)/gcd(a, b);}
bool cmp(string a,string b)
{

}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t; cin>>t;
    while(t--)
    {
        int n; cin>>n;
        vector<string> a(n); int zero = 0, one = 0;
        for(int i=0;i<n;++i) {cin>>a[i]; for(auto l : a[i]) if(l=='1') one++; else zero++;}
        //sort(a.begin(),a.end(),cmp);
        int ans = 0;
        for(int i=0;i<a.size();++i)
        {
            int curr = a[i].size(), temp = one, temp2 = zero; bool val = true;
            if(curr&1)
            {
                while(curr>0)
                {
                    if(curr==1)
                    {
                        if(temp)
                        {
                            temp--;
                            curr--;
                        }
                        else if(temp2) temp2--,curr--;
                        else
                        {
                            val = false; break;
                        }
                    }
                    else
                    {
                        if(temp>=2) temp-=2,curr-=2;
                        else if(temp2>=2) temp2-=2,curr-=2;
                        else
                        {
                            val = false; break;
                        }
                    }
                }
            }
            else
            {
                while(curr>0)
                {
                    if(temp>=2) temp-=2,curr-=2;
                    else if(temp2>=2) temp2-=2,curr-=2;
                    else
                    {
                        val = false; break;
                    }
                }
            }
            if(val) ans++,one=temp,zero=temp2;
        }
        cout<<ans<<'\n';
    }
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b){return (1ll*a*b)/gcd(a, b);}
bool cmp(string a,string b)
{

}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t; cin>>t;
    while(t--)
    {
        int n; cin>>n;
        vector<string> a(n); int zero = 0, one = 0;
        for(int i=0;i<n;++i) {cin>>a[i]; for(auto l : a[i]) if(l=='1') one++; else zero++;}
        sort(a.begin(),a.end(),cmp); int ans = 0;
        for(int i=0;i<a.size();++i)
        {
            int curr = a[i].size(), temp = one, temp2 = zero; bool val = true;
            if(curr&1)
            {
                while(curr>0)
                {
                    if(curr==1)
                    {
                        if(temp)
                        {
                            temp--;
                            curr--;
                        }
                        else if(temp2) temp2--,curr--;
                        else
                        {
                            val = false; break;
                        }
                    }
                    else
                    {
                        if(temp>=2) temp-=2,curr-=2;
                        else if(temp2>=2) temp2-=2,curr-=2;
                        else
                        {
                            val = false; break;
                        }
                    }
                }
            }
            else
            {
                while(curr>0)
                {
                    if(temp>=2) temp-=2,curr-=2;
                    else if(temp2>=2) temp2-=2,curr-=2;
                    else
                    {
                        val = false; break;
                    }
                }
            }
            if(val) ans++,one=temp,zero=temp2;
        }
        cout<<ans<<'\n';
    }
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b){return (1ll*a*b)/gcd(a, b);}
bool cmp(string a,string b)
{
    return a.size() < b.size();
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t; cin>>t;
    while(t--)
    {
        int n; cin>>n;
        vector<string> a(n); int zero = 0, one = 0;
        for(int i=0;i<n;++i) {cin>>a[i]; for(auto l : a[i]) if(l=='1') one++; else zero++;}
        sort(a.begin(),a.end(),cmp);
        int ans = 0;
        for(int i=0;i<a.size();++i)
        {
            int curr = (a[i].size()/2)*2;
            while(curr>0)
            {
                if(one>=2) one-=2,curr-=2;
                else if(zero>=2) zero-=2,curr-=2;
                else
                {
                    break;
                }
            }
            if(curr==0) ans++;
        }
        cout<<ans<<'\n';
    }
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int read() {
	char c = getchar();
	int x = 0, f = 1;
	for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	return x * f;
}
string s;
signed main() {
	string s;
	int T = read();
	while(T--) {
		int n = read(), ans = 0, one = 0, k = n;
		while(k--) {
			cin >> s;
			ans += s.length() % 2;
			for(int i = 0; i < s.length(); i++)
				if(s[i] == '1') one++;
		}
		if(ans >= one % 2) printf("%d\n", n);
		else printf("%d\n", n - 1);
	}
	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pii;
typedef pair<pii,pii> piiii;
typedef vector<pii> vii;
typedef vector<ll> vi;
typedef queue<ll> qi;
typedef queue<char> qc;
typedef queue<string> qs;
typedef vector<char> vc;
typedef vector<string> vs;
typedef map<char,ll> mpci;
typedef map<ll,ll> mpii;
typedef map<string,ll> mpsi;
typedef set<ll> sei;
typedef set<char> sec;
typedef set<string> ses;
typedef stack<ll> si;
typedef stack<char> sc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pll> vpll;
typedef vector<pdd> vdd;
typedef unsigned int uint;
typedef long double ld;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vii> vvii;
/*=====================================================================*/
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define sz(a) (int)(a.size())
#define len(a) (int)(a.length())
#define all(s) (s).begin(),(s).end()
#define fi first
#define se second
#define be begin
#define en end
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define forn(i,p,n) for(int i=p;i<=n;i++)
#define ford(i,p,n) for(int i=n-1;i>=p;i--)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();++i)
#define zero(a) memset(a,0,sizeof(a))
#define number(a,num) memeset(a,num,sizeof(a))

/*=====================================================================*/

inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
inline void write(long long x) {
  static long long sta[35];
  long long top = 0;
  do {
    sta[top++] = x % 10, x /= 10;
  } while (x);
  while (top) putchar(sta[--top] + 48);
  puts("");
}
/*======================================================================*/
bool prime(int n)
{
	if(n==0||n==1)
	  return false;
	for(int i=2;i*i<=n;i++)
	  if(n%i==0)
	    return false;
	return true;
}
/*======================================================================*/
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
/*======================================================================*/
int main()
{
  /*
	ios_base::sync_with_stdio(0);
	cin(tie);
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
  */
  /*====================================================================*/
    int q;
    cin>>q;
    while(q--)
    {
    	int n;
    	cin>>n;
        int t=0,sum=0;
        for(int i=1;i<=n;i++)
		{
			string s;
            cin>>s;
            if(s.size()%2)
			  sum++;
            for(int j=0;j<s.size();j++)
              if(s[j]=='1')
				t++;
        }
        if(t%2==1)
		{
            if(sum>=1)
              cout<<n<<endl;
            else
              cout<<n-1<<endl;
        }
        else
          cout<<n<<endl;
    }
  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int t, n, i, j, k, l, s, f, m, a[51];
char c[51];
int main()
{
	scanf("%d", &t);
	while (t > 0)
	{
		--t;
		scanf("%d", &n);
		k = m = s = 0;
		for (i = 1; i <= n; i++)
		{
			scanf("%s", c);
			l = strlen(c);
			if ((l & 1) == 1) ++s;
			else
			{
				a[++f] = l;
				for (j = 0; j < l; j++)
					if (c[j] == '0') ++m;
					else ++k;
			}
		}
		sort(a + 1, a + f + 1);
		if ((m & 1) == 1 && s > 0) m += k;
		else m += k - 2;
		for(i=1;i<=f;i++)
			if (m >= a[i])
			{
				++s;
				m -= a[i];
			}
		printf("%d\n", s);
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int t, n, i, j, k, l, s, f, m, a[51];
char c[51];
int main()
{
	scanf("%d", &t);
	while (t > 0)
	{
		--t;
		scanf("%d", &n);
		k = m = s = f = 0;
		for (i = 1; i <= n; i++)
		{
			scanf("%s", c);
			l = strlen(c);
			if ((l & 1) == 1) ++s;
			else
			{
				a[++f] = l;
				for (j = 0; j < l; j++)
					if (c[j] == '0') ++m;
					else ++k;
			}
		}
		sort(a + 1, a + f + 1);
		if ((m & 1) == 1 && s == 0) m += k - 2;
		else m += k;
		for (i = 1; i <= f; i++)
			if (m >= a[i])
			{
				++s;
				m -= a[i];
			}
		printf("%d\n", s);
	}
	return 0;
}


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

int n;
int ji,ou;

int main()
{
    int t;
    cin>>t;
    string s;
    while(t--)
    {
        ji=0,ou=0;
        cin>>n;
        long long one=0,zero=0;
        for(int k=0;k<n;k++)
        {
            cin>>s;
            int len=s.size();
            if(len&1)ji++;
            else ou++;
            for(int i=0;i<len;i++)
            {
                if(s[i]=='1')one++;
                else zero++;
            }
        }
        if((one&1&&ji>0)||one%2==0)cout<<n<<endl;
        else cout<<n-1<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int a,b,c,T,n;
int main()
{
	cin>>T;
	while(T--)
	{
		a=b=c=0;
		string s;
		cin>>n;
		for(int i=0;i<n;i++)
		{
			cin>>s;
			for(int j=0;j<s.size();j++)
			{
				if(s[j]=='0')
					a++;
				else
					b++;
			}
			c+=s.size()%2;
		}
		if(c%2)
		{
			if((a%2+b%2)%2==1)
				cout<<n<<endl;
			else
				cout<<n-1<<endl;
		}
		else
		{
			if((a%2+b%2)%2==1||(a%2+b%2)>c)
				cout<<n-1<<endl;
			else
				cout<<n<<endl;
		}
	}
	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string.h>

int t, n;
char s[75][75];

int main() {
    scanf("%d", &t);
    for (int i = 1; i <= t; ++ i) {
        scanf("%d", &n);
        int sum1 = 0, sum2 = 0, sum3 = 0;
        for (int j = 1; j <= n; ++ j)
            scanf("%s", s[j]), sum2 += strlen(s[j]), sum3 ^= strlen(s[j]) & 1;
        for (int j = 1; j <= n; ++ j)
            for (int k = 0; k < strlen(s[j]); ++ k)
                sum1 += s[j][k] - '0';
        if (((sum2 - sum1) & 1) ^ (sum1 & 1))
            printf("%d", n);
        else
            printf("%d", n - 1);
        puts("");
    }
    return 0;
}


#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string.h>

int t, n;
char s[75][75];

int main() {
    scanf("%d", &t);
    for (int i = 1; i <= t; ++ i) {
        scanf("%d", &n);
        int sum1 = 0, sum2 = 0, sum3 = 0;
        for (int j = 1; j <= n; ++ j)
            scanf("%s", s[j]), sum2 += strlen(s[j]), sum3 += strlen(s[j]) & 1;
        for (int j = 1; j <= n; ++ j)
            for (int k = 0; k < strlen(s[j]); ++ k)
                sum1 += s[j][k] - '0';
        if (((((sum2 - sum1) & 1) ^ (sum1 & 1)) == sum3 & 1) && ((((sum2 - sum1) & 1) + (sum1 & 1)) <= sum3))
            printf("%d", n);
        else
            printf("%d", n - 1);
        puts("");
    }
    return 0;
}


#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string.h>

int t, n;
char s[75][75];

int main() {
    scanf("%d", &t);
    for (int i = 1; i <= t; ++ i) {
        scanf("%d", &n);
        int sum1 = 0, sum2 = 0;
        for (int j = 1; j <= n; ++ j)
            scanf("%s", s[j]), sum2 += strlen(s[j]);
        for (int j = 1; j <= n; ++ j)
            for (int k = 0; k < strlen(s[j]); ++ k)
                sum1 += s[j][k] - '0';
        if ((((sum2 - sum1) & 1) ^ (sum1 & 1)) ^ (sum2 & 1))
            printf("%d", n - 1);
        else
            printf("%d", n);
        puts("");
    }
    return 0;
}


//QAQ
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string.h>

int t, n;
char s[75][75];

int main() {
    scanf("%d", &t);
    for (int i = 1; i <= t; ++ i) {
        scanf("%d", &n);
        int sum1 = 0, sum2 = 0, sum3 = 0;
        for (int j = 1; j <= n; ++ j)
            scanf("%s", s[j]), sum2 += strlen(s[j]), sum3 += strlen(s[j]) & 1;
        for (int j = 1; j <= n; ++ j)
            for (int k = 0; s[j][k]; ++ k)
                sum1 += s[j][k] - '0';
        if (((((sum2 - sum1) & 1) ^ (sum1 & 1)) == (sum3 & 1)) && ((((sum2 - sum1) & 1) + (sum1 & 1)) <= sum3))
            printf("%d\n", n);
        else
            printf("%d\n", n - 1);
    }
    return 0;
}


#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string.h>

int t, n;
char s[75][75];

int main() {
    scanf("%d", &t);
    for (int i = 1; i <= t; ++ i) {
        scanf("%d", &n);
        int sum1 = 0, sum2 = 0, sum3 = 0;
        for (int j = 1; j <= n; ++ j)
            scanf("%s", s[j]), sum2 += strlen(s[j]), sum3 += strlen(s[j]) & 1;
        for (int j = 1; j <= n; ++ j)
            for (int k = 0; s[j][k]; ++ k)
                sum1 += s[j][k] - '0';
        if (((((sum2 - sum1) & 1) ^ (sum1 & 1)) == (sum3 & 1)) && ((((sum2 - sum1) & 1) + (sum1 & 1)) <= sum3))
            printf("%d\n", n);
        else
            printf("%d\n", n - 1);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int T;
int n;
string s[100];
void solve(){
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>s[i];
	int c0=0,c1=0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<s[i].size();j++){
			if(s[i][j]=='0')
				c0++;
			else
				c1++;
		}
	}
	int ret=0;
	for(int i=1;i<=n;i++){
		if(s[i].size()%2==0){//偶数，两半偶
			for(int ze=0;ze<=s[i].size();ze+=2){
				if(ze<=c0&&(s[i].size()-ze)<=c1){
					c0-=ze;
					c1-=(s[i].size()-ze);
					ret++;
					break;
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		if(s[i].size()%2==1){
			for(int ze=0;ze<=s[i].size();ze++){
				if(ze<=c0&&(s[i].size()-ze)<=c1){
					c0-=ze;
					c1-=(s[i].size()-ze);
					ret++;
					break;
				}
			}
		}
	}
	cout<<ret<<endl;
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>T;
	while(T--)
		solve();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int T;
int n;
string s[100];
void solve(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>s[i];
	}
	int c0=0;
	bool yj=false;
	for(int i=1;i<=n;i++){
		yj|=(s[i].size()%2==1);
		for(int j=0;j<s[i].size();j++)
			if(s[i][j]=='0')
				c0++;
	}
	cout<<(((yj)||(c0%2==0))?n:n-1)<<endl;
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>T;
	while(T--)
		solve();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int T,n,jj,jo,oo,c0,c1;
string s;
void solve(){
	cin>>n;
	jj=jo=oo=0;
	for(int i=1;i<=n;i++){
		cin>>s;
		c0=c1=0;
		for(int j=0;j<s.size();j++){
			if(s[j]=='0') c0++;
			else c1++;
		}
		if(c0%2==0&&c1%2==0) oo++;
		else if(c0%2==1&&c1%2==1) jj++;
		else jo++;
	}
	jj%=2;
	if(!jj) cout<<n<<endl;
	else{
		if(jo) cout<<n<<endl;
		else cout<<n-1<<endl;
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>T;
	while(T--) solve();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int T,n,cnt0,cnt1;
string s[60];
void solve(){
	cnt0=cnt1=0;
	cin>>n;
	for(int x=1;x<=n;x++){
		cin>>s[x];
		for(int i=0;i<s[x].size();i++){
			if(s[x][i]=='0')
				cnt0++;
			if(s[x][i]=='1')
				cnt1++;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(s[i].size()%2==0){
			for(int ze=0;ze<=s[i].size();ze+=2){
				if(ze<=cnt0&&(s[i].size()-ze)<=cnt1){
					cnt0-=ze;
					cnt1-=(s[i].size()-ze);
					ans++;
					break;
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		if(s[i].size()%2==1){
			for(int ze=0;ze<=s[i].size();ze++){
				if(ze<=cnt0&&(s[i].size()-ze)<=cnt1){
					cnt0-=ze;
					cnt1-=(s[i].size()-ze);
					ans++;
					break;
				}
			}
		}
	}
	cout<<ans<<endl;
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>T;
	while(T--)
		solve();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int T;
int n;
string s[100];
void solve(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>s[i];
	}
	int c0,c1;
	int oo=0,jj=0,oj=0;
	bool yj=false;
	for(int i=1;i<=n;i++){
		c0=c1=0;
		for(int j=0;j<s[i].size();j++){
			if(s[i][j]=='0')
				c0++;
			else
				c1++;
		}
		if(c0%2==0&&c1%2==0)
			oo++;
		else if(c0%2==1&&c1%2==1)
			jj++;
		else
			oj++;
	}
	jj%=2;
	if(jj==0)
		cout<<n<<endl;
	else{
		if(oj)
			cout<<n<<endl;
		else
			cout<<n-1<<endl;
	}
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>T;
	while(T--)
		solve();
	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
string a;
int main(){
	int t,d,ans,s,flag=0,tem;
	cin>>t;
	for(int i=0;i<t;i++){
		cin>>d;
		ans=tem=flag=0;
		for(int j=0;j<d;j++){
			cin>>a;
			s=a.size();
		    if(s%2){ans++;flag=1;}
		else{
			for(int i=0;i<s;i++)
			if(a[i]=='0')tem++;
			if(tem%2) ans++;
		}tem=0;
	}if(!flag)printf("%d\n",ans);else printf("%d\n",d);}
	return 0;
}


#include<iostream>
#include<string>
using namespace std;
string a;
int main(){
	int t,d,s,ans,tem;
	cin>>t;
	for(int i=0;i<t;i++){
		cin>>d;
		ans=tem=0;
		for(int j=0;j<d;j++){
			cin>>a;
			s=a.size();
		    if(s%2){ans++;continue;}
		    else{
		    	for(int k=0;k<s;k++)
		    		if(a[k]=='0')tem++;
		    	if(tem%2==0)ans++;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include<iostream>
#include<string>
using namespace std;
string a;
int main(){
	int t,d,ans,s,k,l,flag=0,tem;
	cin>>t;
	for(int i=0;i<t;i++){
		cin>>d;
		ans=tem=flag=l=k=0;
		for(int j=0;j<d;j++){
			cin>>a;
			s=a.size();
		    if(s%2){ans++;flag=1;k+=s;}
		else{
			for(int i=0;i<s;i++)
			if(a[i]=='0')tem++;
			if(tem%2==0)ans++;
		}tem=0;
	}if(d-ans<=k)printf("%d\n",d);else printf("%d\n",d-1);}
	return 0;
}


#include<iostream>
#include<string>
using namespace std;
string a;
int main(){
	int t,d,ans,s,k,l,tem;
	cin>>t;
	for(int i=0;i<t;i++){
		cin>>d;
		ans=tem=l=k=0;
		for(int j=0;j<d;j++){
			cin>>a;
			s=a.size();
		    if(s%2){ans++;k+=s;}
		else{
			for(int i=0;i<s;i++)
			if(a[i]=='0'){l++;tem++;}
			if(l%2==0)ans++;
		}l=0;}
		if(d-ans<=k||tem%2==0)printf("%d\n",d);else printf("%d\n",d-1);}
	return 0;
}


#include<iostream>
#include<string>
using namespace std;
string a;
int main(){
	int t,d,ans,s,k,l,flag=0,tem;
	cin>>t;
	for(int i=0;i<t;i++){
		cin>>d;
		ans=tem=flag=l=k=0;
		for(int j=0;j<d;j++){
			cin>>a;
			s=a.size();
		    if(s%2){ans++;flag=1;k+=s;}
		else{
			for(int i=0;i<s;i++)
			if(a[i]=='0')tem++;
		}}
		if(d-ans<=k||tem%2==0)printf("%d\n",d);else printf("%d\n",d-1);}
	return 0;
}