#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        string s;
        cin >> s;
        int c = 0,d=0,cnt = 0;
        for(int i = 0;i < s.length();++i)
        {
            if(s[i] == '(')
            {
                c++;
            }
            else if(s[i] == ')')
            {
                if(c>0)
                {
                    c--;
                    cnt++;
                }
            }
            if(s[i] == '[')
            {
                d++;
            }
            else if(s[i] == ']')
            {
                if(d>0)
                {
                    d--;
                    cnt++;
                }
            }
        }
        cout << cnt << endl;
    }
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		string s;
		cin>>s;
		int cnt=0, br1=0, br2=0;
		for(int i=0;i<s.length();i++)
		{
			if(s[i]=='(')
				br1++;
			else if(s[i]=='[')
				br2++;
			else if(s[i]==')' && br1>0)
			{
				br1--;
				cnt++;
			}
			else if(s[i]==']' && br2>0)
			{
				br2--;
				cnt++;
			}
		}
		cout<<cnt<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		string s;
		cin>>s;
		int cntt=0, br1=0, br2=0;
		for(int i=0;i<s.length();i++)
		{
			if(s[i]=='(')
				br1++;
			else if(s[i]=='[')
				br2++;
			else if(s[i]==')' && br1>0)
			{
				br1--;
				cntt++;
			}
			else if(s[i]==']' && br2>0)
			{
				br2--;
				cntt++;
			}
		}
		cout<<cntt<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		string s;
		cin>>s;
		int ans=0, br1=0, br2=0;
		for(int i=0;i<s.length();i++)
		{
			if(s[i]=='(')
				br1++;
			else if(s[i]=='[')
				br2++;
			else if(s[i]==')' && br1>0)
			{
				br1--;
				ans++;
			}
			else if(s[i]==']' && br2>0)
			{
				br2--;
				ans++;
			}
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		string s;
		cin>>s;
		stack<int> st1;
		stack<int> st2;
		int cnt=0;
		for(int i=0;i<s.length();i++)
		{
			if(s[i]=='(')
				st1.push(s[i]);
			else if(s[i]==')' && st1.top()=='(')
			{
				st1.pop();
				cnt++;
			}
		}
		for(int i=0;i<s.length();i++)
		{
			if(s[i]=='[')
				st2.push(s[i]);
			else if(s[i]==']' && st2.top()=='[')
			{
				st2.pop();
				cnt++;
			}
		}
		cout<<cnt<<endl;
	}
}


#include<bits/stdc++.h>
#include <cctype>
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
typedef long double LD;
typedef long long LL;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
const int N = 3e5, M = N;

int getMin(int arr[], int n)
{
  return *min_element(arr, arr + n);
}

int getMax(int arr[], int n)
{
  return *max_element(arr, arr + n);
}

void solve()
{
  //int i,j,n,m,min_=INT16_MAX,max_=INT16_MIN;
  long long n, x;
  int i;
  long long int sum = 0;
  vector<int> v;
  cin >> n;
  fo(i,n)
  {
    cin >> x;
    v.push_back(x);
    sum = sum + x;
  }
  long long c1 = ceil((sum *1.0) / (n - 1));

  long long s = c1 * (n - 1);

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

  if (v[n - 1] > c1)
    s = v[n - 1] * (n - 1);

  cout << s-sum << endl;

}

int main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  srand(chrono::high_resolution_clock::now().time_since_epoch().count());

  int t = 1;
  cin >> t;
  while(t--)
  {
    solve();
  }
  return 0;
}


#include<bits/stdc++.h>
#include <cctype>
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
typedef long double LD;
typedef long long LL;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
const int N = 3e5, M = N;

int getMin(int arr[], int n)
{
  return *min_element(arr, arr + n);
}

int getMax(int arr[], int n)
{
  return *max_element(arr, arr + n);
}

void solve()
{
  //int i,j,n,m,min_=INT16_MAX,max_=INT16_MIN;
  string s;
  cin>>s;
  int n=s.size();
  int total=0;
  int t1=0;
  int t2=0;
  for(int i=0;i<n;i++)
  {
    if(s[i]=='(')
      t1++;
    if(s[i]=='[')
      t2++;
    if(s[i]==']')
    {
      if(t2>0)
      {
        total++;
        t2--;
      }
    }
    if(s[i]==')')
    {
      if(t1>0)
      {
        total++;
        t1--;
      }
    }
  }
  cout<<total<<"\n";

}

int main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  srand(chrono::high_resolution_clock::now().time_since_epoch().count());

  int t = 1;
  cin >> t;
  while(t--)
  {
    solve();
  }
  return 0;
}


#include<bits/stdc++.h>
#include <cctype>
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
typedef long double LD;
typedef long long LL;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
const int N = 3e5, M = N;

void solve()
{
  int i,j,n,m;
  string s;
  cin>>s;
  int correct=0;
  fo(i,s.length())
  {
    if(s[i]=='(')
    {
      for(j=i+1;j<s.length();j++)
      {
        if(s[j]==')')
        {
          correct++;
          s[j]='0';
          s[i]='0';
          break;
        }
      }
    }

    if(s[i]=='[')
    {
      for(j=i+1;j<s.length();j++)
      {
        if(s[j]==']')
        {
          correct++;
          s[j]='0';
          s[i]='0';
          break;
        }
      }
    }
  }
  cout<<correct;
}

int main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  srand(chrono::high_resolution_clock::now().time_since_epoch().count());

  int t = 1;
  cin >> t;
  while(t--)
  {
    solve();
  }
  return 0;
}


#include<bits/stdc++.h>
#include <cctype>
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
typedef long double LD;
typedef long long LL;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
const int N = 3e5, M = N;

void solve()
{
  int i,j,n,m;
  string s;
  cin>>s;
  int correct=0;
  fo(i,s.length())
  {
    if(s[i]=='(')
    {
      for(j=i+1;j<s.length();j++)
      {
        if(s[j]==')')
        {
          correct++;
          s[j]='0';
          s[i]='0';
          break;
        }
      }
    }

    if(s[i]=='[')
    {
      for(j=i+1;j<s.length();j++)
      {
        if(s[j]==']')
        {
          correct++;
          s[j]='0';
          s[i]='0';
          break;
        }
      }
    }
  }
  cout<<correct<<endl;
}

int main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  srand(chrono::high_resolution_clock::now().time_since_epoch().count());

  int t = 1;
  cin >> t;
  while(t--)
  {
    solve();
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        long long int n,i,cnt=0,cnt1=0,cnt2=0;
        n=s.length();
        for(i=0;i<n;i++)
        {

            if(s[i]=='(')
            cnt1++;
            else if(s[i]=='[')
            cnt2++;

            if(s[i]==')' && cnt1>0)
            {
            cnt1--;
            cnt++;
            }
            else if(s[i]==']' && cnt2>0)
            {
                cnt2--;
                cnt++;
            }

        }

        cout<<cnt<<'\n';
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        long long int n=s.length(),i;
        vector<long long int> v1,v2,v3,v4;
        long long int min1=0,min2=0,cnt=0;
        for(i=0;i<n;i++)
        {
            if(s[i]=='(')
            v1.push_back(i);
            if(s[i]==')')
            v2.push_back(i);
            if(s[i]=='[')
            v3.push_back(i);
            if(s[i]==']')
            v4.push_back(i);
        }

        min1=min(v1.size(),v2.size());
        min2=min(v3.size(),v4.size());
        for(i=0;i<min1;i++)
        {
            if(v1[i]<v2[(v2.size()-i-1)])
            cnt++;
        }
          for(i=0;i<min2;i++)
        {
            if(v3[i]<v4[v4.size()-i-1])
            cnt++;
        }
        cout<<cnt<<endl;

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        long long int n=s.length(),i;
        vector<long long int> v1,v2,v3,v4;
        long long int min1=0,min2=0,cnt=0;
        for(i=0;i<n;i++)
        {
            if(s[i]=='(')
            v1.push_back(i);
            if(s[i]==')')
            v2.push_back(i);
            if(s[i]=='[')
            v3.push_back(i);
            if(s[i]==']')
            v4.push_back(i);
        }
        min1=min(v1.size(),v2.size());
        min2=min(v3.size(),v4.size());
        for(i=0;i<min1;i++)
        {
            if(v1[i]<v2[i])
            cnt++;
        }
          for(i=0;i<min2;i++)
        {
            if(v3[i]<v4[i])
            cnt++;
        }
        cout<<cnt<<endl;

    }
    return 0;
}


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

#define int long long
#define fl(a) for(int i=0;i<a;i++)
#define fli(a) for(int i=a-1;i>=0;i--)
#define pb push_back()

void solve(){
string s;
cin>>s; //()[]

stack<char> st1;
stack<char> st2;

st1.push('0');
st2.push('0');

int count = 0;
for(int i=0;i<s.length();i++){
if(s[i]==')' && st1.top() == '('){
    st1.pop();
    count++;
}
else if(s[i]=='('){
    st1.push('(');
}
else if(s[i]==']' && st2.top() == '['){
    st2.pop();
    count++;
}
else if(s[i]=='['){
    st2.push('[');
}
}

cout<<count<<"\n";
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

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

    solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define orr ||
#define mod 1000000007
#define pb push_back
#define usi unordered_set<int>
#define umii unordered_map<int,int>
#define mp make_pair
#define pl pair<int,int>
#define vi vector<int>
#define endl ("\n")
#define pi (3.141592653589)
#define rloop(n) for(int i=n-1;i>=0;i--)
#define loop(i,k,n) for(int i=k;i<n;i++)

void fastio()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	cout<<fixed<<setprecision(10);
}

bool isPrime(int n)
{
    // Corner case
    if (n <= 1)
        return false;

    // Check from 2 to n-1
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}

int32_t main(){
    fastio();
int t;cin>>t;
while(t--){
    string s;
    cin>>s;
    int l=0,m=0,c=0;
    for(int i=0;i<s.size();i++){
	if(s[i]=='(')l++;
    else if(s[i]=='[')m++;
	else if(s[i]==')')if(l>0){l--;c++;}
	else if(s[i]==']')if(m>0){m--;c++;}

}
 cout<<c<<endl;
}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define orr ||
#define mod 1000000007
#define pb push_back
#define usi unordered_set<int>
#define umii unordered_map<int,int>
#define mp make_pair
#define pl pair<int,int>
#define vi vector<int>
#define endl ("\n")
#define pi (3.141592653589)
#define rloop(n) for(int i=n-1;i>=0;i--)
#define loop(i,k,n) for(int i=k;i<n;i++)

void fastio()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	cout<<fixed<<setprecision(10);
}

bool isPrime(int n)
{
    // Corner case
    if (n <= 1)
        return false;

    // Check from 2 to n-1
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}

int32_t main(){
    fastio();
int t;cin>>t;
while(t--){
    string s;
    cin>>s;
    int l=0,m=0,c=0;
    for(int i=0;i<s.size();i++){
	if(s[i]=='(')l++;
    else if(s[i]=='[')m++;
	else if(s[i]==')')if(l>0){l--;c++;}
	else if(s[i]==']')if(m>0){m--;c++;}

}
 cout<<c<<endl<<;
}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define orr ||
#define mod 1000000007
#define pb push_back
#define usi unordered_set<int>
#define umii unordered_map<int,int>
#define mp make_pair
#define pl pair<int,int>
#define vi vector<int>
#define endl ("\n")
#define pi (3.141592653589)
#define rloop(n) for(int i=n-1;i>=0;i--)
#define loop(i,k,n) for(int i=k;i<n;i++)

void fastio()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	cout<<fixed<<setprecision(10);
}

bool isPrime(int n)
{
    // Corner case
    if (n <= 1)
        return false;

    // Check from 2 to n-1
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}

int32_t main(){
    fastio();
int t;cin>>t;
while(t--){
    string s;
    cin>>s;
    int l=0,m=0,c=0;
    for(int i=0;i<s.length();i++){
	if(s[i]=='(')l++;
    else if(s[i]=='[')m++;
	else if(s[i]==')')if(l>0){l--;c++;}
	else if(s[i]==']')if(m>0){m--;c++;}

}
 cout<<c<<endl;
}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define orr ||
#define mod 1000000007
#define pb push_back
#define usi unordered_set<int>
#define umii unordered_map<int,int>
#define mp make_pair
#define pl pair<int,int>
#define vi vector<int>
#define endl ("\n")
#define pi (3.141592653589)
#define rloop(n) for(int i=n-1;i>=0;i--)
#define loop(i,k,n) for(int i=k;i<n;i++)

void fastio()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	cout<<fixed<<setprecision(10);
}

bool isPrime(int n)
{
    // Corner case
    if (n <= 1)
        return false;

    // Check from 2 to n-1
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}

int32_t main(){
    fastio();
int t;cin>>t;
while(t--){
    string s;
    cin>>s;
    int sm=0;
    int bg=0;
    int c=0;
    for(int i=0;i<s.size();i++){
	if(s[i]=='(')sm++;
    else if(s[i]=='[')bg++;
	else if(s[i]==')'){
            if(sm>0){
                    sm--;
                    c++;}
    }
	else if(s[i]==']'){
            if(bg>0){
                    bg--;
            c++;}
    }

}
 cout<<c<<endl;
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef  long long int ll;
#define fio ios_base::sync_with_stdio(NULL),cin.tie(0),cout.tie(0)
#define endl "\n"
#define ft first
#define sd second
int main()
{
    fio;
    int tc;
    cin>>tc;
    while(tc--)
    {
        string s;
        ll i,cnt=0,sb=0,bb=0;
        cin>>s;
        for(i=0;i<s.size();i++)
        {
            if(s[i]=='(')
              {
                  sb++;
              }
            else if(s[i]==')')
              {
                  if(sb>0)
                   cnt++;
                  sb--;
              }
            else if(s[i]=='[')
              {
                  bb++;
              }
              else
              {   if(bb>0)
                  cnt++;
                  bb--;

              }

        }
        cout<<cnt<<endl;

    }

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef  long long int ll;
#define fio ios_base::sync_with_stdio(NULL),cin.tie(0),cout.tie(0)
#define endl "\n"
#define ft first
#define sd second
int main()
{
    fio;
    int tc;
    cin>>tc;
    while(tc--)
    {
        string s;
        ll i,cnt=0,sb=0,bb=0,cnt1=0;
        cin>>s;
        for(i=0;i<s.size();i++)
        {
            if(s[i]=='(')
              {
                  sb++;
              }
            else if(s[i]==')')
              {
                  if(sb>0)
                   cnt++;
                  sb--;
              }
            else if(s[i]=='[')
              {
                  bb++;
              }
              else
              {   if(bb>0)
                  cnt++;
                  bb--;

              }

        }
        for(i=s.size()-1;i>=0;i--)
        {
            if(s[i]=='(')
              {
                  if(sb>0)
                   cnt1++;
                  sb++;
              }
            else if(s[i]==')')
              {

                  sb--;
              }
            else if(s[i]=='[')
              {
                  if(bb>0)
                  cnt1++;
                  bb++;
              }
              else
              {
                  bb--;

              }

        }
        cout<<max(cnt,cnt1)<<endl;

    }

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef  long long int ll;
#define fio ios_base::sync_with_stdio(NULL),cin.tie(0),cout.tie(0)
#define endl "\n"
#define ft first
#define sd second
int main()
{
    fio;
    int tc;
    cin>>tc;
    while(tc--)
    {
        string s;
        ll i,cnt=0,sb=0,bb=0;
        cin>>s;
        for(i=0;i<s.size();i++)
        {
            if(s[i]=='(')
              {
                  sb++;
              }
            else if(s[i]==')')
              {
                  if(sb>0)
                   {
                       cnt++;
                       sb--;
                   }
              }
            else if(s[i]=='[')
              {
                  bb++;
              }
              else
              {   if(bb>0)
                  {
                      cnt++;
                      bb--;
                  }

              }

        }
        cout<<cnt<<endl;

    }

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef  long long int ll;
#define fio ios_base::sync_with_stdio(NULL),cin.tie(0),cout.tie(0)
#define endl "\n"
#define ft first
#define sd second
int main()
{
    fio;
    int tc;
    cin>>tc;
    while(tc--)
    {
        string s;
        ll i,cnt=0,sb=0,bb=0,cnt1=0;
        cin>>s;
        for(i=0;i<s.size();i++)
        {

             if(s[i]==')' && sb>0)
              {
                  cnt++;
                  sb--;
              }

              if(s[i]==']' && bb>0)
              {   cnt++;
                  bb--;

              }
              if(s[i]=='(')
              {
                  sb++;
              }
              if(s[i]=='[')
              {
                  bb++;
              }

        }
        cout<<cnt<<endl;

    }

	return 0;
}


/*      _     _
       |_) | (_  |\/| | |   |    /\  |__|
       |_) |  _) |  | | |__ |__ /--\ |  |
*/

#include<bits/stdc++.h>
typedef long long     ll;
typedef unsigned int  ui;

#define text          freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define pi            3.1415926535897932384626433832795
#define root          100000
#define num           1e17
#define mod           1000000007
#define fix(a)        fixed<<setprecision(a)
#define sc1(a)        scanf("%d",&a)
#define sc2(a,b)      scanf("%d%d",&a,&b)
#define sc3(a,b,c)    scanf("%d%d%d",&a,&b,&c)
#define pb(n)         push_back(n)
#define fl(i,a,b,c)   for(int i=a; i<=b; i+=c)
#define fl2(i,a,b,c)  for(int i=a; i>=b; i-=c)
#define st(a)         sort(a.begin(),a.end())
#define rst(a)        sort(a.rbegin(),a.rend())
#define l(a)          a.size()

using namespace std;

int main()
{
/*#ifndef ONLINE_JODGE
	text
#endif
*/
	int t;
	cin >> t;
	while (t--) {
		string a;
		cin >> a;
		map<char, int>p;
		int x = 0;
		fl(i, 0, l(a) - 1, 1) {
			if (!p[a[i]] && a[i] == '(') {
				fl2(j, l(a) - 1, i + 1, 1) {
					if (!p[a[j]] && a[j] == ')') {
						p[a[i]]++; p[a[j]]++;
						x++;
					}
				}
			}
			else if (!p[a[i]] && a[i] == '[') {
				fl2(j, l(a) - 1, i + 1, 1) {
					if (!p[a[j]] && a[j] == ']') {
						p[a[i]]++; p[a[j]]++;
						x++;
					}
				}
			}
		}
		cout << x << "\n";
	}

}


/*      _     _
       |_) | (_  |\/| | |   |    /\  |__|
       |_) |  _) |  | | |__ |__ /--\ |  |
*/

#include<bits/stdc++.h>
typedef long long     ll;
typedef unsigned int  ui;

#define text          freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define pi            3.1415926535897932384626433832795
#define root          100000
#define num           1e17
#define mod           1000000007
#define fix(a)        fixed<<setprecision(a)
#define sc1(a)        scanf("%d",&a)
#define sc2(a,b)      scanf("%d%d",&a,&b)
#define sc3(a,b,c)    scanf("%d%d%d",&a,&b,&c)
#define pb(n)         push_back(n)
#define fl(i,a,b,c)   for(int i=a; i<=b; i+=c)
#define fl2(i,a,b,c)  for(int i=a; i>=b; i-=c)
#define st(a)         sort(a.begin(),a.end())
#define rst(a)        sort(a.rbegin(),a.rend())
#define l(a)          a.size()

using namespace std;

int main()
{
/*#ifndef ONLINE_JODGE
	text
#endif
*/
	int t;
	cin >> t;
	while (t--) {
		string a;
		cin >> a;
		map<char, int>p;
		int x = 0;
		fl(i, 0, l(a) - 1, 1) {
			if (!p[a[i]] && a[i] == '(') {
				fl(j, i + 1, l(a) - 1, 1) {
					if (!p[a[j]] && a[j] == ')') {
						p[a[i]]++; p[a[j]]++;
						x++;
					}
				}
			}
			else if (!p[a[i]] && a[i] == '[') {
				fl(j, i + 1, l(a) - 1, 1) {
					if (!p[a[j]] && a[j] == ']') {
						p[a[i]]++; p[a[j]]++;
						x++;
					}
				}
			}
		}
		cout << x << "\n";
	}

}


/*      _     _
       |_) | (_  |\/| | |   |    /\  |__|
       |_) |  _) |  | | |__ |__ /--\ |  |
*/

#include<bits/stdc++.h>
typedef long long     ll;
typedef unsigned int  ui;

#define text          freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define pi            3.1415926535897932384626433832795
#define root          100000
#define num           1e17
#define mod           1000000007
#define fix(a)        fixed<<setprecision(a)
#define sc1(a)        scanf("%d",&a)
#define sc2(a,b)      scanf("%d%d",&a,&b)
#define sc3(a,b,c)    scanf("%d%d%d",&a,&b,&c)
#define pb(n)         push_back(n)
#define fl(i,a,b,c)   for(int i=a; i<=b; i+=c)
#define fl2(i,a,b,c)  for(int i=a; i>=b; i-=c)
#define st(a)         sort(a.begin(),a.end())
#define rst(a)        sort(a.rbegin(),a.rend())
#define l(a)          a.size()

using namespace std;

int main()
{
/*#ifndef ONLINE_JODGE
	text
#endif*/

	int t;
	cin >> t;
	while (t--) {
		string a;
		cin >> a;
		map<char, int>p;
		int x = 0;
		fl(i, 0, l(a) - 1, 1) {
			if (!p[i] && a[i] == '(') {
				fl2(j, l(a) - 1, i + 1, 1) {
					if (!p[j] && a[j] == ')') {
						p[i]++; p[j]++;
						x++; break;
					}
				}
			}
			else if (!p[i] && a[i] == '[') {
				fl2(j, l(a) - 1, i + 1, 1) {
					if (!p[j] && a[j] == ']') {
						p[i]++; p[j]++;
						x++; break;
					}
				}
			}
		}
		cout << x << "\n";
	}

}


/*      _     _
       |_) | (_  |\/| | |   |    /\  |__|
       |_) |  _) |  | | |__ |__ /--\ |  |
*/

#include<bits/stdc++.h>
typedef long long     ll;
typedef unsigned int  ui;

#define text          freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define pi            3.1415926535897932384626433832795
#define root          100000
#define num           1e17
#define mod           1000000007
#define fix(a)        fixed<<setprecision(a)
#define sc1(a)        scanf("%d",&a)
#define sc2(a,b)      scanf("%d%d",&a,&b)
#define sc3(a,b,c)    scanf("%d%d%d",&a,&b,&c)
#define pb(n)         push_back(n)
#define fl(i,a,b,c)   for(int i=a; i<=b; i+=c)
#define fl2(i,a,b,c)  for(int i=a; i>=b; i-=c)
#define st(a)         sort(a.begin(),a.end())
#define rst(a)        sort(a.rbegin(),a.rend())
#define l(a)          a.size()

using namespace std;

int main()
{
/*#ifndef ONLINE_JODGE
	text
#endif*/

	int t;
	cin >> t;
	while (t--) {
		string a;
		cin >> a;
		//map<char, int>p;
		int x = 0, p = 0, q = 0;
		fl(i, 0, l(a) - 1, 1) {
			if (a[i] == '(') {
				p++;
			}
			else if (a[i] == ')') {
				if (p > 0) {
					p--; x++;
				}
			}
			else if (a[i] == '[') {
				q++;
			}
			else if (a[i] == ']') {
				if (q > 0) {
					q--; x++;
				}
			}
		}
		cout << x << "\n";
	}

}


/*      _     _
       |_) | (_  |\/| | |   |    /\  |__|
       |_) |  _) |  | | |__ |__ /--\ |  |
*/

#include<bits/stdc++.h>
typedef long long     ll;
typedef unsigned int  ui;

#define text          freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define pi            3.1415926535897932384626433832795
#define root          100000
#define num           1e17
#define mod           1000000007
#define fix(a)        fixed<<setprecision(a)
#define sc1(a)        scanf("%d",&a)
#define sc2(a,b)      scanf("%d%d",&a,&b)
#define sc3(a,b,c)    scanf("%d%d%d",&a,&b,&c)
#define pb(n)         push_back(n)
#define fl(i,a,b,c)   for(int i=a; i<=b; i+=c)
#define fl2(i,a,b,c)  for(int i=a; i>=b; i-=c)
#define st(a)         sort(a.begin(),a.end())
#define rst(a)        sort(a.rbegin(),a.rend())
#define l(a)          a.size()

using namespace std;

int main()
{
/*#ifndef ONLINE_JODGE
	text
#endif*/

	int t;
	cin >> t;
	while (t--) {
		string a;
		cin >> a;
		map<char, int>p;
		int x = 0;
		fl(i, 0, l(a) - 1, 1) {
			if (!p[i] && a[i] == '(') {
				fl2(j, l(a) - 1, i + 1, 1) {
					if (!p[j] && a[j] == ')') {
						p[i]++; p[j]++;
						x++; break;
					}
				}
			}
			else if (!p[a[i]] && a[i] == '[') {
				fl2(j, l(a) - 1, i + 1, 1) {
					if (!p[j] && a[j] == ']') {
						p[i]++; p[j]++;
						x++; break;
					}
				}
			}
		}
		cout << x << "\n";
	}

}


/*      _     _
       |_) | (_  |\/| | |   |    /\  |__|
       |_) |  _) |  | | |__ |__ /--\ |  |
*/

#include<bits/stdc++.h>
typedef long long     ll;
typedef unsigned int  ui;

#define text          freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define pi            3.1415926535897932384626433832795
#define root          100000
#define num           1e17
#define mod           1000000007
#define fix(a)        fixed<<setprecision(a)
#define sc1(a)        scanf("%d",&a)
#define sc2(a,b)      scanf("%d%d",&a,&b)
#define sc3(a,b,c)    scanf("%d%d%d",&a,&b,&c)
#define pb(n)         push_back(n)
#define fl(i,a,b,c)   for(int i=a; i<=b; i+=c)
#define fl2(i,a,b,c)  for(int i=a; i>=b; i-=c)
#define st(a)         sort(a.begin(),a.end())
#define rst(a)        sort(a.rbegin(),a.rend())
#define l(a)          a.size()

using namespace std;

int main()
{
/*#ifndef ONLINE_JODGE
	text
#endif*/

	int t;
	cin >> t;
	while (t--) {
		string a;
		cin >> a;
		map<char, int>p;
		int x = 0;
		fl(i, 0, l(a) - 1, 1) {
			if (!p[a[i]] && a[i] == '(') {
				fl2(j, l(a) - 1, i + 1, 1) {
					if (!p[a[j]] && a[j] == ')') {
						p[a[i]]++; p[a[j]]++;
						x++;break;
					}
				}
			}
			else if (!p[a[i]] && a[i] == '[') {
				fl2(j, l(a) - 1, i + 1, 1) {
					if (!p[a[j]] && a[j] == ']') {
						p[a[i]]++; p[a[j]]++;
						x++;break;
					}
				}
			}
		}
		cout << x << "\n";
	}

}


#include <iostream>
#include <string>

using namespace std;

int main()
{
    int t;
    cin>>t;
    int o[t];
    for(int i=0;i<t;i++)
    {
        string a;
        cin>>a;
        int a1=0,b1=0,s=0;
        for(char x:a)
        {
            if(x=='(')
                a1++;
            else if(x=='[')
                b1++;
            else if(x==')')
            {
                if(a1>0)
                    {
                        a1--;
                        s++;
                    }
                else a1=0;
            }
            else if(x==']')
            {
                if(b1>0)
                    {
                        b1--;
                        s++;
                    }
                else b1=0;
            }
        }
        o[i]=s;
    }
    for(int i=0;i<t;i++)
        cout<<o[i]<<endl;
    return 0;
}


#include <iostream>
#include <cstring>
#include <iomanip>

using namespace std;

int main()
{
    int t;
    cin>>t;
    char str[200000];
    double st[t];
    for(int x=0;x<t;x++)
    {
        cin>>str;
        double len=strlen(str);
        int s=0,q1=0,y=0,q2=0;
        r:
        for(int i=y;i<len;i++) //it is going in one more time than expected to
        {
            if(str[i]=='(' && !q1)
              {
                y=i+1;
                for(int j=i+1;j<len;j++)
                {
                      double w=0;
                      if(str[j]==')')
                      {
                          s++;
                          str[i]='0';
                          str[j]='0';
                          w++;
                      }
                      if(!w) q1++;
                }
               goto r;
              }
              else if(str[i]=='[' && !q2)
              {
                y=i+1;
                for(int j=i+1;j<len;j++)
                {
                      double w=0;
                      if(str[j]==']')
                      {
                          s++;
                          str[i]='0';
                          str[j]='0';
                          w++;
                      }
                      if(!w) q2++;
                }
               goto r;
              }
        }
        st[x]=s;
    }
    for(int z=0;z<t;z++)
    {
        cout<<std::fixed<<std::setprecision(0);
        cout<<st[z]<<endl;

    }

    return 0;
}


#include <iostream>
#include <cstring>
#include <iomanip>

using namespace std;

int main()
{
    int t;
    cin>>t;
    char str[200000];
    double st[t];
    for(int x=0;x<t;x++)
    {
        cin>>str;
        double len=strlen(str);
        int s=0,q1=0,y=0,q2=0;
        r:
        for(int i=y;i<len;i++) //it is going in one more time than expected to
        {
            if(str[i]=='(' && !q1)
              {
                y=i+1;
                for(int j=i+1;j<len;j++)
                {
                      double w=0;
                      if(str[j]==')')
                      {
                          s++;
                          str[i]='0';
                          str[j]='0';
                          w++;
                      }
                   //   if(!w) q1++;
                }
               goto r;
              }
              else if(str[i]=='[' && !q2)
              {
                y=i+1;
                for(int j=i+1;j<len;j++)
                {
                      double w=0;
                      if(str[j]==']')
                      {
                          s++;
                          str[i]='0';
                          str[j]='0';
                          w++;
                      }
                //      if(!w) q2++;
                }
               goto r;
              }
        }
        st[x]=s;
    }
    for(int z=0;z<t;z++)
    {
        cout<<std::fixed<<std::setprecision(0);
        cout<<st[z]<<endl;

    }

    return 0;
}


#include <iostream>
#include <cstring>

using namespace std;

int main()
{
    int t;
    cin>>t;
    char str[200000];
    double st[t];
    for(int x=0;x<t;x++)
    {
        cin>>str;
        double len=strlen(str);
        int s=0,q1=0,y=0,q2=0;
        r:
        for(int i=y;i<len;i++) //it is going in one more time than expected to
        {
            if(str[i]=='(' && !q1)
              {
                y=i+1;
                for(int j=i+1;j<len;j++)
                {
                      double w=0;
                      if(str[j]==')')
                      {
                          s++;
                          str[i]='0';
                          str[j]='0';
                          w++;
                      }
                      if(!w) q1++;
                }
               goto r;
              }
              else if(str[i]=='[' && !q2)
              {
                y=i+1;
                for(int j=i+1;j<len;j++)
                {
                      double w=0;
                      if(str[j]==']')
                      {
                          s++;
                          str[i]='0';
                          str[j]='0';
                          w++;
                      }
                      if(!w) q2++;
                }
               goto r;
              }
        }
        st[x]=s;
    }
    for(int z=0;z<t;z++)
        cout<<st[z]<<endl;
    return 0;
}


//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<set>
#include<unordered_set>
#include<list>
#include<bitset>
#include<map>
#include<iterator>
#include<algorithm>
#include<utility>
#include<functional>
#include<numeric>
#include<iomanip>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define nl "\n"
#define NL co<<nl
#define vd " "
#define F first
#define S second
#define fo(a,b) for(i=a;i<b;i++)
#define Fo(a,b) for(i=a;i>=b;i--)
#define fo1(a,b) for(j=a;j<b;j++)
#define Fo1(a,b) for(j=a;j>=b;j--)
#define fo2(a,b,c) for(i=a;i<=b;i+=c)
#define Fo2(a,b,c) for(i=a;i<=b;i-=c)
#define pb push_back
#define mp make_pair
#define popf pop_front
#define popb pop_back
#define eb emplace_back
#define ins insert
#define sf scanf
#define pf printf
#define all(v)  v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define tc(T) while(T--)
#define vec vector
#define co cout
#define d(x) co<<to_string(x)<<vd<<x<<vd
#define yes co<<"YES\n"
#define no co<<"NO\n"
#define yes2 co<<"Yes\n"
#define no2 co<<"No\n"
#define stol(s) stoll(s,nullptr,10)
#define vl vec<ll>
#define usl unordered_set<ll>
#define ml map<ll,ll>
#define mllit map<ll,ll>::iterator
#define mplll map<pair<ll,ll>,ll>
#define msl map<string,ll>
#define vpl vec<pair<ll,ll>>
#define sl set<ll>
#define mlb map<ll,bool>
#define vb vec<bool>
#define spll set<pair<ll,ll>>
#define spsl set<pair<string,ll>>
#define slit set<ll>::iterator
#define spllit set<pair<ll,ll>>::iterator
#define in(a,n) fo(0,n){cin>>a[i];}
#define vin(a,n) fo(0,n){cin>>q;a.eb(q);}
#define vsinin(a) {cin>>q;a.pb(q);}
#define vpin(a,n) fo(0,n){cin>>q>>w;a.pb({q,w});}
#define vpout(b,n) fo(0,n){co<<b[i].F<<vd<<b[i].S<<nl;}
#define out(a,n) fo(0,n){cout<<a[i]<<vd;}
#define in2d(a,n,m) fo(0,n){for(j=0;j<m;j++){cin>>a[i][j];}}
#define out2d(a,n,m) fo(0,n){for(j=0;j<m;j++){co<<a[i][j]<<vd;} co<<nl;}
#define factors(a,n) if(n==1){a.pb(1);} else{fo(1,sqrt(n)+1){if(n%i==0){a.pb(i);if(i!=n/i){a.pb(n/i);}}}sort(all(a));}
#define MX(a) *max_element(a,a+n)
#define MN(a) *min_element(a,a+n)
#define VMX(a) *max_element(all(a))
#define VMN(a) *min_element(all(a))
#define lowb(a,x) (std::lower_bound(a.begin(),a.end(),x)-a.begin())
#define upb(a,x) (std::upper_bound(a.begin(),a.end(),x)-a.begin())
#define beg begin()
#define rbeg rbegin()
#define ren rend()
#define en end()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
ll T=1,inf=100000000000000000,mod=1000000007;
ld pi=acos(0);
inline ll ncr(ll n,ll r)
{
    ll l=n,f2=1,l2=n-r,i=1,j=1;
    if (r != 0||r!=n)
    {
        while (l2!=0||l!=r)
        {
            i*= l;
            j*= l2;
            ll m = gcd(i,j);
            i/= m;
            j/= m;
            l--;
            l2--;
        }
    }
    else i = 1;
    return i;
}
inline ll dig_sum(ll n) {
    ll v=n,sum=0,i;
    while(v) {
        sum+=v%10;
        v/=10;
    }
    return sum;

}
inline bool ckprime(ll n) {
    if(n%2==0&&n!=2) return 0;
    else if(n==2) return 1;
    else {
        ll v=sqrt(n),flag=1,i;
        for(i=3; i<=v; i+=2) {
            if(n%i==0) {
                flag=0;
                break;
            }
        }
        return flag;
    }

}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> T;
    while(T--)
    {
        ll n,sz=1,ans=0,blag=0,u,mn=0,ev=0,mx=0,mini,i,v,q,p,j,k,w,h,l,m,x,y,od=0,total=0,cc=0,pp=0,flag=0,klag=0,sum=0;
        string s,s1,s2;
        cin>>s;
        n=s.size();
        fo(0,n) {
            if(s[i]=='['||s[i]==']') s2.pb(s[i]);
            else s1.pb(s[i]);
        }
        fo(0,s1.size()) {
            if(s1[i]=='(') cc++;
            else {
                if(cc>0) ans++;
                cc--;
                if(cc<0)cc=0;
            }
        }
        cc=0;
        fo(0,s2.size()) {
            if(s2[i]=='[') cc++;
            else {
                if(cc>0) ans++;
                cc--;
                if(cc<0) cc=0;
            }
        }
        co<<ans<<nl;

    }
    return 0;
}
/*If I get WA-
check special cases for 0,1,2...
if it seems in 1200-check special cases or bugs.
if seems 1300/1400/1500 -missed any cases.
if get wa again and again after adding case-Change logic.
*/


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define nl "\n"
#define NL co<<nl
#define vd " "
#define F first
#define S second
#define fo(a,b) for(i=a;i<b;i++)
#define Fo(a,b) for(i=a;i>=b;i--)
#define fo1(a,b) for(j=a;j<b;j++)
#define Fo1(a,b) for(j=a;j>=b;j--)
#define fo2(a,b,c) for(i=a;i<=b;i+=c)
#define Fo2(a,b,c) for(i=a;i<=b;i-=c)
#define pb push_back
#define mp make_pair
#define popf pop_front
#define popb pop_back
#define eb emplace_back
#define ins insert
#define sf scanf
#define pf printf
#define all(v)  v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define tc(T) while(T--)
#define vec vector
#define co cout
#define d(x) co<<to_string(x)<<vd<<x<<vd
#define yes co<<"YES\n"
#define no co<<"NO\n"
#define yes2 co<<"Yes\n"
#define no2 co<<"No\n"
#define stol(s) stoll(s,nullptr,10)
#define vl vec<ll>
#define usl unordered_set<ll>
#define ml map<ll,ll>
#define mllit map<ll,ll>::iterator
#define mplll map<pair<ll,ll>,ll>
#define msl map<string,ll>
#define vpl vec<pair<ll,ll>>
#define sl set<ll>
#define mlb map<ll,bool>
#define vb vec<bool>
#define spll set<pair<ll,ll>>
#define spsl set<pair<string,ll>>
#define slit set<ll>::iterator
#define spllit set<pair<ll,ll>>::iterator
#define in(a,n) fo(0,n){cin>>a[i];}
#define vin(a,n) fo(0,n){cin>>q;a.eb(q);}
#define vsinin(a) {cin>>q;a.pb(q);}
#define vpin(a,n) fo(0,n){cin>>q>>w;a.pb({q,w});}
#define vpout(b,n) fo(0,n){co<<b[i].F<<vd<<b[i].S<<nl;}
#define out(a,n) fo(0,n){cout<<a[i]<<vd;}
#define in2d(a,n,m) fo(0,n){for(j=0;j<m;j++){cin>>a[i][j];}}
#define out2d(a,n,m) fo(0,n){for(j=0;j<m;j++){co<<a[i][j]<<vd;} co<<nl;}
#define factors(a,n) if(n==1){a.pb(1);} else{fo(1,sqrt(n)+1){if(n%i==0){a.pb(i);if(i!=n/i){a.pb(n/i);}}}sort(all(a));}
#define MX(a) *max_element(a,a+n)
#define MN(a) *min_element(a,a+n)
#define VMX(a) *max_element(all(a))
#define VMN(a) *min_element(all(a))
#define lowb(a,x) (std::lower_bound(a.begin(),a.end(),x)-a.begin())
#define upb(a,x) (std::upper_bound(a.begin(),a.end(),x)-a.begin())
#define beg begin()
#define rbeg rbegin()
#define ren rend()
#define en end()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
ll T=1,inf=100000000000000000,mod=1000000007;
int main()
{
   //ios::sync_with_stdio(0);
    //cin.tie(0);
    cin >> T;
    while(T--)
    {
        ll n,sz=1,ans=0,blag=0,u,mn=0,ev=0,mx=0,mini,i,v,q,p,j,k,w,h,l,m,x,y,od=0,total=0,cc=0,pp=0,flag=0,klag=0,sum=0;
        string s,s1,s2;
        cin>>x>>y;
        if(x>y) swap(x,y);
        ans+=2*x;
        y-=x;
        x=0;
        if(y-x>=1) {
            ans++;
            y--;
        }
        ans+=2*y;
        co<<ans<<nl;

    }
    return 0;
}
/*If I get WA-
check special cases for 0,1,2...
if it seems in 1200-check special cases or bugs.
if seems 1300/1400/1500 -missed any cases.
if get wa again and again after adding case-Change logic.
*/


  /*Ekeshwar Jhode*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        ll l=s.length(),count=0,count1=0,count2=0,count3=0,count4=0,flag=1,glag=1;
        for(ll i=0;i<s.length();i++){
            if(s[i]=='(' ){
                count1++;
                flag=0;
            }
            else if(s[i]==')' && flag==0){
                count2++;
                flag==1;
            }
            if(count1==count2 && count1!=0){
                if(count1!=0){
                count++;
                count1=0;
                count2=0;
                }
            }
            if(s[i]=='['){
                count3++;
                glag=0;
            }
            else if(s[i]==']' && glag==0){
                count4++;
                glag=1;
            }
            if(count3==count4 && count3!=0){
                if(count4!=0){
                count++;
                count3=0;
                count4=0;
                }
            }
        }
        cout<<count<<'\n';
    }
    return 0;
}


  /*Ekeshwar Jhode*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        ll l=s.length(),count=0,count1=0,count2=0,count3=0,count4=0;
        for(ll i=0;i<s.length();i++){
            if(s[i]=='('){
                count1++;
            }
            else if(s[i]=='['){
                count2++;
            }
            else if(s[i]==')' && count1>0){
                count++;
                count1--;
            }
            else if(s[i]==']' && count2>0){
                count++;
                count2--;
            }
        }
        cout<<count<<'\n';
    }
    return 0;
}


  /*Ekeshwar Jhode*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        ll l=s.length(),count1=0;
        for(ll i=0;i<s.length();i++){
            if(s[i]=='(' && count(s.begin()+i+1, s.end(), ')') >0 ){
                ll u=i;
                for(ll j=i+1;j<s.length();j++){
                    if(s[j]==')'){
                        s[i]='0';
                       s[j]='0';
                        count1++;
                        break;
                    }
                }
            }
            else if(s[i]=='[' && count(s.begin()+i+1, s.end(), ']') >0 ){
                for(ll j=i+1;j<s.length();j++){
                    if(s[j]==']'){
                      s[i]='0';
                      s[j]='0';
                        count1++;
                        break;
                    }
                }
            }
        }
        cout<<count1<<'\n';
    }
    return 0;
}


  /*Ekeshwar Jhode*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        ll l=s.length(),count=0;
        for(ll i=0;i<s.length();i++){
            if(s[i]=='('){
                ll u=i;
                for(ll j=i+1;j<s.length();j++){
                    if(s[j]==')'){
                        s.erase(i,1);
                       // cout<<s<<'\n';
                        s.erase(j-1,1);
                       // cout<<s<<'\n';
                        count++;
                        i=-1;
                        break;
                    }
                }
            }
            else if(s[i]=='['){
                for(ll j=i+1;j<s.length();j++){
                    if(s[j]==']'){
                        s.erase(i,1);
                       // cout<<s<<'\n';
                        s.erase(j-1,1);
                       // cout<<s<<'\n';
                        count++;
                        i=-1;
                        break;
                    }
                }
            }
        }
        cout<<count<<'\n';
    }
    return 0;
}


  /*Ekeshwar Jhode*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        ll l=s.length(),count=0;
        for(ll i=0;i<s.length();i++){
            if(s[i]=='('){
                ll u=i;
                for(ll j=i+1;j<s.length();j++){
                    if(s[j]==')'){
                        //s.erase(i,1);
                        s[i]='0';
                       // cout<<s<<'\n';
                     //    s.erase(j-1,1);
                       // cout<<s<<'\n';
                       s[j]='0';
                        count++;
                        // i=u;
                        break;
                    }
                }
            }
            else if(s[i]=='['){
                for(ll j=i+1;j<s.length();j++){
                    if(s[j]==']'){
                       // s.erase(i,1);
                      //  cout<<s<<'\n';
                      //  s.erase(j-1,1);
                      //  cout<<s<<'\n';
                      s[i]='0';
                      s[j]='0';
                        count++;
                        break;
                    }
                }
            }
        }
        cout<<count<<'\n';
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int ans;
bool f[101];
int main()
{
	int n;
	cin>>n;
	int x;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			scanf("%d",&x);
			if(x==1) f[i]=1;
			if(x==2) f[j]=1;
			if(x==3) f[i]=1,f[j]=1;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(!f[i]) ans++;
	}
	cout<<ans<<endl;
	if(!ans) return 0;
	for(int i=1;i<=n;i++)
	{
		if(!f[i]) printf("%d ",i);
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;
const int M=102;
int n,a,f[M],ans;

int main()
{
	cin>>n; memset(f,true,sizeof(f));
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
	{
		cin>>a;
		if(a==1) f[i]=false;
		if(a==2) f[j]=false;
		if(a==3) f[i]=f[j]=false;
	}
	for(int i=1;i<=n;i++)
	if(f[i]) ans++;
	cout<<ans<<endl;
	for(int i=1;i<=n;i++)
	if(f[i]) cout<<i<<' ';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[101][101];
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=n;++j)
		{
			scanf("%d",&a[i][j]);
		}
	}
	bool b[101]={0};
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<i;++j)
		{
			if(a[i][j]<=0) continue;
			else if(a[i][j]==3)
			{
				b[i]=b[j]=1;
			}
			else if(a[i][j]==1) b[i]=1;
			else if(a[i][j]==2) b[j]=1;
		}
	}
	int cnt=0;
	for(int i=1;i<=n;++i)
	{
		cnt+=(!b[i]);
	}
	printf("%d\n",cnt);
	for(int i=1;i<=n;++i)
	{
		if(!b[i]) cout<<i<<" ";
	}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long a,s,d[106],f,g,h,j,k,l,i,n,m;
vector<int> v;
main(){
cin>>n;
for(i=0;i<n;i++){
    k=0;
    for(j=0;j<n;j++){
    cin>>a;
    if(i<j && (a==1 || a==3)) k=1;

    }
    if(k==0) v.push_back(i+1);

}
cout<<v.size()<<endl;
for(i=0;i<v.size();i++){
    cout<<v[i]<<" ";
}
}


#include<bits/stdc++.h>
using namespace std;
long long a,s,d[106],f,g,h,j,k,l,i,n,m;
vector<int> v;
main(){
cin>>n;
for(i=0;i<n;i++){
    k=0;
    for(j=0;j<n;j++){
    cin>>a;
    if(i<j && a==1 || a==3) k=1;
    }
    if(k==0) v.push_back(i+1);

}
cout<<v.size()<<endl;
for(i=0;i<v.size();i++){
    cout<<v[i]<<" ";
}
}


#include<bits/stdc++.h>
using namespace std;
long long a,s,d[106],f,g,h,j,k,l,i,n,m;
vector<int> v;
main(){
cin>>n;
for(i=0;i<n;i++){
    k=0;
    for(j=0;j<n;j++){
    cin>>a;
    if(i<j && a==2) k=1;
    if(i>j && a==1) k=1;
    }
    if(k==0) v.push_back(i+1);

}
cout<<v.size()<<endl;
for(i=0;i<v.size();i++){
    cout<<v[i]<<" ";
}
}


#include<bits/stdc++.h>
using namespace std;
long long a,s,d[106],f,g,h,j,k,l,i,n,m;
vector<int> v;
main(){
cin>>n;
for(i=0;i<n;i++){
    k=0;
    for(j=0;j<n;j++){
    cin>>a;
    if(i<j && a==1) k=1;
    }
    if(k==0) v.push_back(i+1);

}
cout<<v.size()<<endl;
for(i=0;i<v.size();i++){
    cout<<v[i]<<" ";
}
}


#include<bits/stdc++.h>
using namespace std;
long long a,s,d[106],f,g,h,j,k,l,i,n,m;
vector<int> v;
main(){
cin>>n;
for(i=0;i<n;i++){
    k=0;
    for(j=0;j<n;j++){
    cin>>a;
    if(a==1 || a==3) k=1;
    }
    if(k==0) v.push_back(i+1);

}
cout<<v.size()<<endl;
for(i=0;i<v.size();i++){
    cout<<v[i]<<" ";
}
}


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

using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    vector<int> goods;
    for(int i = 0; i < n; i++) {
        int good = 1;
        for(int j = 0; j < n; j++) {
            int num;
            scanf("%d", &num);
            if(num == 3 || num == 1) {
                good = 0;
            }
        }
        goods.push_back(good);
    }
    int numGood = 0;
    for(int i = 0; i < goods.size(); i++) {
        if(goods.at(i) == 1) numGood++;
    }
    cout << numGood << "\n";
    for(int i = 0; i < goods.size();  i++) {
        if(goods.at(i) == 1) printf("%d ", i + 1);
    }
}


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

using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    vector<int> goods;
    for(int i = 0; i < n; i++) {
        int good = 1;
        for(int j = 0; j < n; j++) {
            int num;
            scanf("%d", &num);
            if(num == 3 || num == 1) {
                good = 0;
            }
        }
        goods.push_back(good);
    }
    int numGood = 0;
    for(int i = 0; i < goods.size(); i++) {
        if(goods.at(i) == 1) numGood++;
    }
    cout << numGood << "\n";
    for(int i = 0; goods.size(); i < i++) {
        if(goods.at(i) == 1) printf("%d ", i + 1);
    }
}


#include<stdio.h>

using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    int goods[n];
    for(int i = 0; i < n; i++) {
        int good = 1;
        for(int j = 0; j < n; j++) {
            int num;
            scanf("%d", &num);
            if(num == 3 || num == 1) {
                good = 0;
            }
        }
        goods[i] = good;
    }
    int numGood;
    for(int i = 0; i < sizeof(goods)/sizeof(goods[0]); i++) {
        if(goods[i] == 1) numGood++;
    }
    printf("%d\n", numGood);
    for(int i = 0; i < sizeof(goods)/sizeof(goods[0]); i++) {
        if(goods[i] == 1) printf("%d ", i + 1);
    }
}


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

using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    int goods[n];
    for(int i = 0; i < n; i++) {
        int good = 1;
        for(int j = 0; j < n; j++) {
            int num;
            scanf("%d", &num);
            if(num == 3 || num == 1) {
                good = 0;
            }
        }
        goods[i] = good;
    }
    int numGood;
    for(int i = 0; i < sizeof(goods)/sizeof(goods[0]); i++) {
        if(goods[i] == 1) numGood++;
    }
    cout << numGood << "\n";
    for(int i = 0; i < sizeof(goods)/sizeof(goods[0]); i++) {
        if(goods[i] == 1) printf("%d ", i + 1);
    }
}


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

using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    vector<int> goods;
    for(int i = 0; i < n; i++) {
        int good = 1;
        for(int j = 0; j < n; j++) {
            int num;
            scanf("%d", &num);
            if(num == 3 || num == 1) {
                good = 0;
            }
        }
        goods.push_back(good);
    }
    int numGood = 0;
    for(int i = 0; i < goods.size(); i++) {
        if(goods.at(i) == 1) numGood++;
    }
    cout << numGood << "\n";
    for(int i = 0; goods.size() < i;  i++) {
        if(goods.at(i) == 1) printf("%d ", i + 1);
    }
}


#include<iostream>
#include<string>
#include<sstream>
#include<set>
#include<vector>
#include<bitset>
#include<cmath>
#include<map>
#include<algorithm>

#define fo(i,n) for(int i=0;i<n; i++)
#define pii pair<int ,int>
using namespace std;
bool arr[105];
int matrix[100][100];
int n;
int main()
{
	cin >> n;
	fo(i, n)
		arr[i] = 1;
	fo(i,n)
		fo(j, n)
	{
		cin >> matrix[i][j];
	}

	fo(i, n)
		fo(j, n)
	{
		if (matrix[i][j] == 1)
			arr[i] = 0;
		else if (matrix[i][j] == 2)
			arr[j] == 0;
		else if (matrix[i][j] == 3)
			arr[i] = arr[j] = 0;
	}
	int ans = 0;
	fo(i, n)
		if (arr[i] == true )
			ans++;

	cout << ans << endl;
	fo(i, n)
		if (arr[i] == true)
			cout << i+1 << " ";

	return 0;
}


#include<iostream>
#include<string>
#include<sstream>
#include<set>
#include<vector>
#include<bitset>
#include<cmath>
#include<map>
#include<algorithm>

#define fo(i,n) for(int i=0;i<n; i++)
#define pii pair<int ,int>
using namespace std;
bool arr[105];
int matrix[100][100];
int n;
int main()
{
	cin >> n;
	memset(arr, 1, n);
	fo(i,n)
		fo(j, n)
	{
		cin >> matrix[i][j];
	}

	fo(i, n)
		fo(j, n)
	{
		if (matrix[i][j] == 1)
			arr[i] = 0;
		else if (matrix[i][j] == 2)
			arr[j] == 0;
		else if (matrix[i][j] == 3)
			arr[i] = arr[j] = 0;
	}
	int ans = 0;
	fo(i, n)
		if (arr[i] == true )
			ans++;

	cout << ans << endl;;
	fo(i, n)
		if (arr[i] == true)
			cout << i+1 << " ";

	return 0;
}


#include<iostream>
#include<string>
#include<sstream>
#include<set>
#include<vector>
#include<bitset>
#include<cmath>
#include<map>
#include<algorithm>

#define fo(i,n) for(int i=0;i<n; i++)
#define pii pair<int ,int>
using namespace std;
bool arr[105];
int matrix[100][100];
int n;
int main()
{
	cin >> n;
	memset(arr, 1, n);
	fo(i,n)
		fo(j, n)
	{
		cin >> matrix[i][j];
	}

	fo(i, n)
		fo(j, n)
	{
		if (matrix[i][j] == 1)
			arr[i] = 0;
		else if (matrix[i][j] == 2)
			arr[j] == 0;
		else if (matrix[i][j] == 3)
			arr[i] = arr[j] = 0;
	}
	int ans = 0;
	fo(i, n)
		if (arr[i] == true )
			ans++;

	cout << ans << endl;
	fo(i, n)
		if (arr[i] == true)
			cout << i+1 << " ";

	return 0;
}


	#define ss(n)                       scanf("%s",n)
	#define fall(i,a,b)               for(i=a;i<b;i++)
	#define feall(i,a,b)               for(i=a;i<=b;i++)
	typedef long long ll;
	typedef unsigned long long ull;
	#include<bits/stdc++.h>                                  //fill(&a[][],&a[][]+sizeof(a)*sizeofa[][],1);														//vector <pair<int,int> >
	using namespace std;									//.pb(mp());__gcd
	#define pb push_back
	#define mp make_pair
	const int MOD = int(1e9+7);
	int i,j,n,t,flag;
	int main()
	{
		cin>>n;
		int a[n+1][n+1];
		vector <int> b;
		if(n==1)
            {cin>>i;cout<<1<<endl<<1;}
        else{
		fall(i,1,n+1)
           {
               flag=0;
               fall(j,1,n+1)
                {
                    cin>>a[i][j];
                    if (a[i][j]==-1);
                    if(a[i][j]==0||a[i][j]==2)
                    {
                        flag=1;
                    }
                    else{flag=0
                        ;break;}
                }
                if(flag)
                    b.pb(i);
           }
           t=b.size();
		cout<<t<<endl;
		fall (i,0,t)
            cout<<b[i]<<' ';
		}return 0;
	}


	#define ss(n)                       scanf("%s",n)
	#define fall(i,a,b)               for(i=a;i<b;i++)
	#define feall(i,a,b)               for(i=a;i<=b;i++)
	typedef long long ll;
	typedef unsigned long long ull;
	#include<bits/stdc++.h>                                  //fill(&a[][],&a[][]+sizeof(a)*sizeofa[][],1);														//vector <pair<int,int> >
	using namespace std;									//.pb(mp());__gcd
	#define pb push_back
	#define mp make_pair
	const int MOD = int(1e9+7);
	int i,j,n,t,flag;
	int main()
	{
		cin>>n;
		int a[n][n];
		vector <int> b;
		fall(i,1,n+1)
           {
               flag=0;
               fall(j,1,n+1)
                {
                    cin>>a[i][j];
                    if(a[i][j]==0||a[i][j]==-1||a[i][j]==2)
                    {
                        flag=1;
                    }
                    else{flag=0
                        ;break;}
                }
                if(flag)
                    b.pb(i);
           }
           t=b.size();
		cout<<t<<endl;
		fall (i,0,t)
            cout<<b[i]<<' ';
		return 0;
	}


	#define ss(n)                       scanf("%s",n)
	#define fall(i,a,b)               for(i=a;i<b;i++)
	#define feall(i,a,b)               for(i=a;i<=b;i++)
	typedef long long ll;
	typedef unsigned long long ull;
	#include<bits/stdc++.h>                                  //fill(&a[][],&a[][]+sizeof(a)*sizeofa[][],1);														//vector <pair<int,int> >
	using namespace std;									//.pb(mp());__gcd
	#define pb push_back
	#define mp make_pair
	const int MOD = int(1e9+7);
	int i,j,n,t,flag;
	int main()
	{
		cin>>n;
		int a[n+1][n+1];
		vector <int> b;
		fall(i,1,n+1)
            fall(j,1,n+1)
                          cin>>a[i][j];

		fall(i,1,n+1)
           {
               flag=0;
               fall(j,1,n+1)
                {
                    if(a[i][j]==0||a[i][j]==-1||a[i][j]==2)
                    {
                        flag=1;
                    }
                    else{flag=0
                        ;break;}
                }
                if(flag)
                    b.pb(i);
           }
           t=b.size();
		cout<<t<<endl;
		fall (i,0,t)
            cout<<b[i]<<' ';
            return 0;
	}


	#define ss(n)                       scanf("%s",n)
	#define fall(i,a,b)               for(i=a;i<b;i++)
	#define feall(i,a,b)               for(i=a;i<=b;i++)
	typedef long long ll;
	typedef unsigned long long ull;
	#include<bits/stdc++.h>                                  //fill(&a[][],&a[][]+sizeof(a)*sizeofa[][],1);														//vector <pair<int,int> >
	using namespace std;									//.pb(mp());__gcd
	#define pb push_back
	#define mp make_pair
	const int MOD = int(1e9+7);
	int i,j,n,t,flag;
	int main()
	{
		cin>>n;
		int a[n+1][n+1];
		vector <int> b;
		fall(i,1,n+1)
           {
               flag=0;
               fall(j,1,n+1)
                {
                    cin>>a[i][j];
                    if(a[i][j]==0||a[i][j]==-1||a[i][j]==2)
                    {
                        flag=1;
                    }
                    else{flag=0
                        ;break;}
                }
                if(flag)
                    b.pb(i);
           }
           t=b.size();
		cout<<t<<endl;
		fall (i,0,t)
            cout<<b[i]<<' ';
		return 0;
	}


	#define ss(n)                       scanf("%s",n)
	#define fall(i,a,b)               for(i=a;i<b;i++)
	#define feall(i,a,b)               for(i=a;i<=b;i++)
	typedef long long ll;
	typedef unsigned long long ull;
	#include<bits/stdc++.h>                                  //fill(&a[][],&a[][]+sizeof(a)*sizeofa[][],1);														//vector <pair<int,int> >
	using namespace std;									//.pb(mp());__gcd
	#define pb push_back
	#define mp make_pair
	const int MOD = int(1e9+7);
	int i,j,n,t,flag;
	int main()
	{
		cin>>n;
		int a[n+1][n+1];
		vector <int> b;
		if(n==1)
            {cin>>i;cout<<1<<endl<<1;}
        else{
		fall(i,1,n+1)
           {
               flag=0;
               fall(j,1,n+1)
                {
                    cin>>a[i][j];
                    if(a[i][j]==0||a[i][j]==-1||a[i][j]==2)
                    {
                        flag=1;
                    }
                    else{flag=0
                        ;break;}
                }
                if(flag)
                    b.pb(i);
           }
           t=b.size();
		cout<<t<<endl;
		fall (i,0,t)
            cout<<b[i]<<' ';
		}return 0;
	}


#include<bits/stdc++.h>
#define ll long long
#define time ios_base::sync_with_stdio(0);
#define in  freopen("cut.in","r",stdin);
#define out freopen("cut.out","w",stdout);
#define fi first
#define se second
#define pb push_back
#define pf push_front
using namespace std ;
const ll INF = 1e9;
const ll N = 2e5 + 1;
const ll mod = 1e8 ;
const long double eps = 1E-7 ;

int lnt ;
bool used[N] ;
int n , cnt[N] ;
vector < int > V ;
int a[1005][1005] ;
int main ()
{
  cin >> n ;
  for ( int i = 1 ; i <= n ; i++ )
  {
      for ( int j = 1 ; j <= n ; j++ )
      {
          cin >> a[i][j] ;
      }
  }
  for ( int i = 1 ; i <= n ; i++ )
  {
      for ( int j = 1 ; j <= n ; j++ )
      {
          if ( a[i][j] == 1 )
          {
              used[i] = 0 ;
          }
          if ( a[i][j] == 2 )
          {
              used[j] = 0 ;
          }
          if ( a[i][j] == 3 )
          {
              used[i] = 0;
              used[j] = 0;
          }
          if ( a[i][j] == -1 )
          {
              used[i] = 1;
              used[j] = 1;
          }
          if ( a[i][j] == 0 )
          {
              used[i] = 1 ;
              used[j] = 1 ;
          }
      }
   }
  for ( int i = 1 ; i <= n ; i++ )
  {
      if ( used[i] == 1 )
      {
          V.pb(i) ;
      }
  }
  cout << V.size() << endl ;
  for ( int i = 0  ; i < V.size() ; i++ )
  {
      cout << V[i] << " " ;
  }
}


#include<bits/stdc++.h>
#define ll long long
#define time ios_base::sync_with_stdio(0);
#define in  freopen("cut.in","r",stdin);
#define out freopen("cut.out","w",stdout);
#define fi first
#define se second
#define pb push_back
#define pf push_front
using namespace std ;
const ll INF = 1e9;
const ll N = 2e5 + 1;
const ll mod = 1e8 ;
const long double eps = 1E-7 ;

int lnt ;
bool used[N] ;
int n , cnt ;
vector < int > V ;
int a ;
int main ()
{
  cin >> n ;
  for ( int i = 1 ; i <= n ; i++ )
  {
      for ( int j = 1 ; j <= n ; j++ )
      {
          cin >> a ;
          if ( a == 1 )
            used[i]=1 ;
          if ( a == 2 )
            used[j]=1 ;
          if ( a == 3 )
          {
            used[i]=1 ; used[j]=1;
          }
      }
  }
  for ( int i = 1 ; i <= n ; i++ )
  {
      if ( !used[i] )
      {
         cnt++ ;
      }
  }
  cout << cnt << endl ;
  for ( int i = 1 ; i <= n ; i++ )
  {
      if ( !used[i] )
      {
          cout << i << " " ;
       }
  }
}


#include<bits/stdc++.h>
#define ll long long
#define time ios_base::sync_with_stdio(0);
#define in  freopen("cut.in","r",stdin);
#define out freopen("cut.out","w",stdout);
#define fi first
#define se second
#define pb push_back
#define pf push_front
using namespace std ;
const ll INF = 1e9;
const ll N = 2e5 + 1;
const ll mod = 1e8 ;
const long double eps = 1E-7 ;

int lnt ;
int n , cnt[N] ;
int a[1005][1005] ;
int main ()
{
  cin >> n ;
  for ( int i = 1 ; i <= n ; i++ )
  {
      for ( int j = 1 ; j <= n ; j++ )
      {
          cin >> a[i][j] ;
      }
  }
  for ( int i = 1 ; i <= n ; i++ )
  {
      for ( int j = 1 ; j <= n ; j++ )
      {
          if ( a[i][j] == 1 )
          {
              cnt[i]-- ;
          }
          if ( a[i][j] == 2 )
          {
              cnt[j]-- ;
          }
          if ( a[i][j] == 3 )
          {
              cnt[j]-- ;
              cnt[i]-- ;
          }
          if ( a[i][j] == 0 )
          {
              cnt[i]++ ;
              cnt[j]++ ;
          }
      }
  }
  for ( int i = 1 ; i <= n ; i++ )
  {
      if ( cnt[i]!=0 and cnt[i] > 0 )
      {
         lnt++ ;
      }
  }
  cout << lnt << endl;
  for ( int i = 1 ; i <= n ; i++ )
  {
      if ( cnt[i]!=0 and cnt[i] > 0 )
      {
          cout << i << " " ;
      }
  }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define read() freopen("in.txt","r",stdin)
int main()
{
int n ;
while(cin>>n)
{
    int mat[101][101];
    map<int,int> good;
    good.clear();

    for( int i =0; i<n; i++)
    {
        for( int  j =0;j<n; j++)
        {
            cin>>mat[i][j];
        }

    }

    for( int i =0; i<n; i++)
    {
        for( int  j =0;j<n; j++)
        {
            if(mat[i][j]==0)
            {
                good[i]=1;
                good[j]=1;
            }
            else if(mat[i][j]==1) good[i]=0;
            else if( mat[i][j]==2) good[j]=0;
            else if(mat[i][j]==3) {good[i]=0; good[j]=0;}

        }
    }
    vector<int>v;
    for( int i =0; i<n; i++)
    {
        if(good[i]==1)
        {
            v.push_back(i+1);
        }
    }
    cout<<v.size()<<endl;
    if(v.size()>0)
    {
        for( int i =0; i<v.size()-1; i++)
            cout<<v[i]<<" ";
        cout<<v[v.size()-1]<<endl;
    }

}
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define read() freopen("in.txt","r",stdin)
int main()
{
int n ;
while(cin>>n)
{
    int mat[101][101];
    map<int,int> good;
    good.clear();

    for( int i =0; i<n; i++)
    {
        for( int  j =0;j<n; j++)
        {
            cin>>mat[i][j];
        }

    }

    for( int i =0; i<n; i++)
    {
        for( int  j =0;j<n; j++)
        {
            if(mat[i][j]==0)
            {
                good[i]=1;
                good[j]=1;
            }
            else if(mat[i][j]==1) good[i]=0;
            else if( mat[i][j]==2) good[j]=0;
            else if(mat[i][j]==3) {good[i]=0; good[j]=0;}

        }
    }
    vector<int>v;
    for( int i =0; i<n; i++)
    {
        if(good[i]==1)
        {
            v.push_back(i+1);
        }
    }
    cout<<v.size()<<endl;
    sort(v.begin(),v.end());
    if(v.size()>0)
    {
        for( int i =0; i<v.size()-1; i++)
            cout<<v[i]<<" ";
        cout<<v[v.size()-1]<<endl;
    }

}
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define read() freopen("in.txt","r",stdin)
 int mat[1010][1010];
int main()
{
    int n ;
    while(cin>>n)
    {

        map<int,int> good;
        good.clear();

        for( int i =0; i<n; i++)
        {
            for( int  j =0; j<n; j++)
            {
                cin>>mat[i][j];
            }
        }

        for( int i =0; i<n; i++)
        {
            for( int  j =0; j<n; j++)
            {
                if(mat[i][j]==0)
                {
                    good[i]=1;
                    good[j]=1;
                }
                else if(mat[i][j]==1) good[i]=0;
                else if(mat[i][j]==2) good[j]=0;
                else if(mat[i][j]==3)
                {
                    good[i]=0;
                    good[j]=0;
                }

            }
        }
        vector<int>v;
        for( int i =0; i<n; i++)
        {
            if(good[i]==1)
            {
                v.push_back(i+1);
            }
        }
        cout<<v.size()<<endl;
        sort(v.begin(),v.end());
        if(v.size()>0)
        {
            for( int i =0; i<v.size()-1; i++)
                cout<<v[i]<<" ";
            cout<<v[v.size()-1]<<endl;
        }

    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define read() freopen("in.txt","r",stdin)
int mat[1010][1010];
int main()
{
    int n ;
    while(cin>>n)
    {

        map<int,int> good;

        for( int i =0; i<n; i++)
        {
            for( int  j =0; j<n; j++)
            {
                cin>>mat[i][j];
                good[i]=1;
                good[j]=1;
            }
        }

            for( int i =0; i<n; i++)
            {
                for( int  j =0; j<n; j++)
                {

                    if(mat[i][j]==1) good[i]=0;
                    else if(mat[i][j]==2) good[j]=0;
                    else if(mat[i][j]==3)
                    {
                        good[i]=0;
                        good[j]=0;
                    }

                }
            }
            vector<int>v;
            for( int i =0; i<n; i++)
            {
                if(good[i]==1)
                {
                    v.push_back(i+1);
                }
            }
            cout<<v.size()<<endl;
            sort(v.begin(),v.end());
            if(v.size()>0)
            {
                for( int i =0; i<v.size()-1; i++)
                    cout<<v[i]<<" ";
                cout<<v[v.size()-1]<<endl;
            }

    }
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

#define rep(i,n) for(int i = 0, _##i = n; i < _##i; ++i)
#define dwn(i,n) for(int i = n; i >= 0; --i)
#define itr(v, it) for(__typeof(v.begin()) it = v.begin(); it != v.end(); it++)

#define vi vector<int>
#define pb push_back
#define ll long long

#define min(a, b) (a<b?a:b)
#define max(a, b) (a>b?a:b)

#define INF (int) 1e9
#define EPS 1e-9

int main() {

	int cases;
	cin >> cases;

	vector<int> solutions;

	for(int i = 0; i < cases; i++) {
		bool failed = false;
		for(int j = 0; j < cases; j++) {
			int result;
			cin >> result;
			if(result == 1 || result == 3) {
				failed = true;
				break;
			}
		}
		if(!failed)
			solutions.pb(i);
	}

	cout << solutions.size();
	if(solutions.size())
		cout << endl;
	for(int i = 0; i < solutions.size(); i++)
		cout << solutions[i] + 1 << " ";

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

#define rep(i,n) for(int i = 0, _##i = n; i < _##i; ++i)
#define dwn(i,n) for(int i = n; i >= 0; --i)
#define itr(v, it) for(__typeof(v.begin()) it = v.begin(); it != v.end(); it++)

#define vi vector<int>
#define pb push_back
#define ll long long

#define min(a, b) (a<b?a:b)
#define max(a, b) (a>b?a:b)

#define INF (int) 1e9
#define EPS 1e-9

int main() {

	int cases;
	cin >> cases;

	vector<int> solutions;

	for(int i = 0; i < cases; i++) {
		bool failed = false;
		for(int j = 0; j < cases; j++) {
			int result;
			cin >> result;
			if(result == 1 || result == 3) {
				failed = true;
			}
		}
		if(!failed)
			solutions.pb(i);
	}

	cout << solutions.size();
	if(solutions.size())
		cout << endl;
	for(int i = 0; i < solutions.size(); i++)
		cout << solutions[i] + 1 << " ";

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

#define rep(i,n) for(int i = 0, _##i = n; i < _##i; ++i)
#define dwn(i,n) for(int i = n; i >= 0; --i)
#define itr(v, it) for(__typeof(v.begin()) it = v.begin(); it != v.end(); it++)

#define vi vector<int>
#define pb push_back
#define ll long long

#define min(a, b) (a<b?a:b)
#define max(a, b) (a>b?a:b)

#define INF (int) 1e9
#define EPS 1e-9

int main() {

	int cases;
	cin >> cases;

	vector<int> solutions;

	for(int i = 0; i < cases; i++) {
		bool failed = false;
		for(int j = 0; j < cases; j++) {
			int result;
			cin >> result;
			if(result == 1) {
				failed = true;
				break;
			}
		}
		if(!failed)
			solutions.pb(i);
	}

	cout << solutions.size();
	if(solutions.size())
		cout << endl;
	for(int i = 0; i < solutions.size(); i++)
		cout << solutions[i] + 1 << " ";

	return 0;
}


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

int main(){
	int n;
	cin>>n;
	int mat[n][n];
	vector<int> v;
//	v.push_back(0);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>mat[i][j];
			if(mat[i][j]==1){
				v.push_back(i+1);
			}
			if(mat[i][j]==2){
				v.push_back(j+1);
			}
			if(mat[i][j]==3){
				v.push_back(i+1);
				v.push_back(j+1);
			}
		}
	}
	if(n==1){
		cout<<1<<endl<<1; return 0;
	}
/*	for(int i=0;i<v.size();i++){
		cout<<v[i]<<" ";
		} cout<<endl;
	*/
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	/*for(int i=0;i<v.size();i++){
		cout<<v[i]<<" ";
		}
		cout<<endl;*/
	cout<<n-v.size()<<endl;
	for(int i=1; i<=n; i++){
		for(int j=0;j<v.size();j++){
			if(i!=v[j]){
				cout<<i<<" ";
			}
		}
	}

	return 0;
}


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

int main(){
	int n;
	cin>>n;
	int mat[n][n];
	vector<int> v;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>mat[i][j];
			if(mat[i][j]==1){
				v.push_back(i+1);
			}
			if(mat[i][j]==2){
				v.push_back(j+1);
			}
			if(mat[i][j]==3){
				v.push_back(i+1);
				v.push_back(j+1);
			}
		}
	}
	if(n==1){
		cout<<1<<endl<<1; return 0;
	}
/*	for(int i=0;i<v.size();i++){
		cout<<v[i]<<" ";
		} cout<<endl;
	*/
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	/*for(int i=0;i<v.size();i++){
		cout<<v[i]<<" ";
		}
		cout<<endl;*/
	cout<<n-v.size()<<endl;
	for(int i=1, j=0;i<=n;i++, j++){
		if(i!=v[j]){
			cout<<i<<" ";
		}
	}

	return 0;
}


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

int main(){
	int n;
	cin>>n;
	int mat[n][n];
	vector<int> v;
	v.push_back(0);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>mat[i][j];
			if(mat[i][j]==1){
				v.push_back(i+1);
			}
			if(mat[i][j]==2){
				v.push_back(j+1);
			}
			if(mat[i][j]==3){
				v.push_back(i+1);
				v.push_back(j+1);
			}
		}
	}
	if(n==1){
		cout<<1<<endl<<1; return 0;
	}
/*	for(int i=0;i<v.size();i++){
		cout<<v[i]<<" ";
		} cout<<endl;
	*/
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	/*for(int i=0;i<v.size();i++){
		cout<<v[i]<<" ";
		}
		cout<<endl;*/
	cout<<n-v.size()<<endl;
	for(int i=1; i<=n; i++){
		for(int j=0;j<v.size();j++){
			if(i!=v[j]){
				cout<<i<<" ";
			}
		}
	}

	return 0;
}


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

int main(){
	int n;
	cin>>n;
	int mat[n][n];
	vector<int> v;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>mat[i][j];
			if(mat[i][j]==1){
				v.push_back(i+1);
			}
			if(mat[i][j]==2){
				v.push_back(j+1);
			}
			if(mat[i][j]==3){
				v.push_back(i+1);
				v.push_back(j+1);
			}
		}
	}
	if(n==1){
		cout<<0; return 0;
	}
/*	for(int i=0;i<v.size();i++){
		cout<<v[i]<<" ";
		} cout<<endl;
	*/
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	/*for(int i=0;i<v.size();i++){
		cout<<v[i]<<" ";
		}
		cout<<endl;*/
	cout<<n-v.size()<<endl;
	for(int i=1, j=0;i<=n;i++, j++){
		if(i!=v[j]){
			cout<<i<<" ";
		}
	}

	return 0;
}


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

int main(){
	int n;
	cin>>n;
	int mat[n][n];
	vector<int> v;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>mat[i][j];
			if(mat[i][j]==1){
				v.push_back(i+1);
			}
			if(mat[i][j]==2){
				v.push_back(j+1);
			}
			if(mat[i][j]==3){
				v.push_back(i+1);
				v.push_back(j+1);
			}
		}
	}
	if(n==1){
		cout<<1<<endl<<1; return 0;
	}
/*	for(int i=0;i<v.size();i++){
		cout<<v[i]<<" ";
		} cout<<endl;
	*/
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	/*for(int i=0;i<v.size();i++){
		cout<<v[i]<<" ";
		}
		cout<<endl;*/
	cout<<n-v.size()<<endl;

	for(int i=1, j=0; i<=n; i++){
		if(v[j]!=i){
			cout<<i<<" ";
		}
		else j++;
	}

	return 0;
}


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

int main(){
	int n;
	cin>>n;
	int mat[n][n];
	vector<int> v;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>mat[i][j];
			if(mat[i][j]==1){
				v.push_back(i+1);
			}
			if(mat[i][j]==2){
				v.push_back(j+1);
			}
			if(mat[i][j]==3){
				v.push_back(i+1);
				v.push_back(j+1);
			}
		}
	}

/*	for(int i=0;i<v.size();i++){
		cout<<v[i]<<" ";
		} cout<<endl;
	*/
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	/*for(int i=0;i<v.size();i++){
		cout<<v[i]<<" ";
		}
		cout<<endl;*/
	cout<<n-v.size()<<endl;
	for(int i=1, j=0;i<=n;i++, j++){
		if(i!=v[j]){
			cout<<i<<" ";
		}
	}

	return 0;
}
//9223372036854775808


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

int main(){
	int n;
	cin>>n;
	int mat[n][n];
	vector<int> v;
	v.push_back(0);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>mat[i][j];
			if(mat[i][j]==1){
				v.push_back(i+1);
			}
			if(mat[i][j]==2){
				v.push_back(j+1);
			}
			if(mat[i][j]==3){
				v.push_back(i+1);
				v.push_back(j+1);
			}
		}
	}
	if(n==1){
		cout<<1<<endl<<1; return 0;
	}
/*	for(int i=0;i<v.size();i++){
		cout<<v[i]<<" ";
		} cout<<endl;
	*/
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	/*for(int i=0;i<v.size();i++){
		cout<<v[i]<<" ";
		}
		cout<<endl;*/
	cout<<n-v.size()+1<<endl;

	for(int i=1, j=1; i<=n; i++){
		if(v[j]!=i){
			cout<<i<<" ";
		}
		else j++;
	}

	return 0;
}


#include<iostream>
#include<algorithm>

using namespace std;
struct pon
{
    int a;
    int b;
};

bool cmp(pon ob1,pon ob2)
{
    return ob1.a<ob2.a;

}

int main()
{
    int n,counter=0;
    cin>>n;
    int arra[n][n];
    pon arra1[n];
    for(int i=0;i<n;i++){
            arra1[i].a=0;
            arra1[i].b=i+1;
        for(int j=0;j<n;j++){
            cin>>arra[i][j];
        }
    }
    int fl=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<i;j++){
            if(arra[i][j]==0){
                counter++;

            }
            else if(arra[i][j]==1){
                arra1[i].a++;
            }
            else if(arra[i][j]==2){
                arra1[j].a++;
            }
        }
    }
    sort(arra1,arra1+n,cmp);
    cout<<counter<<endl;
    if(counter>0){
        for(int i=0;i<counter;i++){
            cout<<arra1[i].b<<" ";
        }
    }
}


#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
    int n,counter=0;
    cin>>n;
    int arra[n][n];
    int arra1[n];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>arra[i][j];
        }
    }

    int fl=0,flag=0;
    for(int i=0;i<n;i++){
        flag=0;
        for(int j=0;j<n;j++){
            if(i!=j){
                if(arra[i][j]==1||arra[i][j]==3){
                    flag=1;
                    break;
                }
            }
        }
        if(flag==0){
            arra1[fl]=i+1;
            counter++;
            fl++;
        }
    }
    //sort(arra1,arra1+n,cmp);
    cout<<counter<<endl;
    if(counter>0){
        for(int i=0;i<counter;i++){
            cout<<arra1[i]<<" ";
        }
    }
}


#include<iostream>
#include<algorithm>

using namespace std;
struct pon
{
    int a;
    int b;
};

bool cmp(pon ob1,pon ob2)
{
    return ob1.a<ob2.a;

}

int main()
{
    int n,counter=0;
    cin>>n;
    int arra[n][n];
    pon arra1[n];
    for(int i=0;i<n;i++){
            arra1[i].a=0;
            arra1[i].b=i+1;
        for(int j=0;j<n;j++){
            cin>>arra[i][j];
        }
    }
    if(n==1){
        cout<<"1"<<endl<<"1"<<endl;
        return 0;
    }
    int fl=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<i;j++){
            if(arra[i][j]==0){
                counter++;

            }
            else if(arra[i][j]==1){
                arra1[i].a++;
            }
            else if(arra[i][j]==2){
                arra1[j].a++;
            }
        }
    }
    sort(arra1,arra1+n,cmp);
    cout<<counter<<endl;
    if(counter>0){
        for(int i=0;i<counter;i++){
            cout<<arra1[i].b<<" ";
        }
    }
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#define N 105
using namespace std;
int i, j, k, l, m, n, q, p;
int a[N][N], b[N];
int main(){
	cin >> n;
	for (i = 0; i < n; ++i)
		for (j = 0; j < n; ++j)
			cin >> a[i][j];

	for (i = 0; i < n; ++i){
		k = 0;
		for (j = 0; j < n; ++j){
			if (a[i][j] != 1 && a[i][j] != 3 && a[i][j] != -1) k++;
		}
		if (k > 0) m++;
	}
	cout << m;
return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#define N 10000
using namespace std;
int i, j, k, l, m, n, q, p;
int a[N][N], b[N];
int main(){
	cin >> n;
	for (i = 0; i < n; ++i)
		for (j = 0; j < n; ++j)
			cin >> a[i][j];

	for (i = 0; i < n; ++i){
		k = 0;
		for (j = 0; j < n; ++j){
			if (a[i][j] != 1 && a[i][j] != 3 && a[i][j] != -1) k++;
		}
		if (k > 0) m++;
	}
	cout << m;
return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#define N 105
using namespace std;
int i, j, k, l, m, n, q, p;
int a[N][N], b[N];
int main(){
	cin >> n;
	for (i = 0; i < n; ++i)
		for (j = 0; j < n; ++j)
			cin >> a[i][j];

	for (i = 0; i < n; ++i){
		k = 0;
		for (j = 0; j < n; ++j){
			if (a[i][j] != 1 && a[i][j] != 3) k++;
		}
		if (k == n) m++, b[i] = 1;
	}
	cout << m << endl;
	for (i = 0; i < n; ++i) if (b[i] == 1) cout << i+1 << " ";
return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#define N 105
using namespace std;
int i, j, k, l, m, n, q, p;
int a[N][N], b[N];
int main(){
	cin >> n;
	for (i = 0; i < n; ++i)
		for (j = 0; j < n; ++j)
			cin >> a[i][j];

	for (i = 0; i < n; ++i){
		k = 0;
		for (j = 0; j < n; ++j){
			if (a[i][j] != 2 && a[i][j] != 3) k++;
		}
		if (k == n) m++, b[i] = 1;
	}
	cout << m << endl;
	for (i = 0; i < n; ++i) if (b[i] == 1) cout << i+1 << " ";
return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int i,j,k,n,m,p;
int ch,cv;
int f[100000];

int main(){
	cin >> n;
	for(i = 0; i < n; i++){
		ch = 0;
		for(j = 0; j < n; j++){
			cin >> p;
			if(p != 1 && p != 3) ch++;
		}
		if (ch == n) {cv++; f[i] = 1;}
	}
	cout << cv << endl;
	for(i = 0; i < n; i++){
		if(f[i] == 1)
		cout << i+1 << " ";
	}
}


#include <bits\stdc++.h>

using namespace std;

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

	int n;
	int a;
	int result[102] = {0};

	cin >> n;
	if (n > 1) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> a;
				if (a == -1 || !a)
					continue;

				if (a == 1)
					result[i+1]++;
				else if (a == 2)
					result[j+1]++;
				else {
					result[i+1]++;
					result[j+1]++;
				}
			}
		}

		int cnt = count (result+1, result+n+1, 0);
		if (cnt) {
			cout << cnt << '\n';
			for (int i = 1; i < n+1; i++) {
				if (!result[i])
					cout << i << ' ';
			}
		}
		else
			cout << 0;
	}
	else {
		cout << "1\n1";
	}
}


#include <bits\stdc++.h>

using namespace std;

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

	int n;
	int a;
	int result[102] = {0};

	cin >> n;
	if (n > 1) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> a;
				if (a == -1 || !a)
					continue;

				if (a == 1)
					result[i+1]++;
				else if (a == 2)
					result[j+1]++;
				else {
					result[i+1]++;
					result[j+1]++;
				}
			}
		}

		int cnt = count (result+1, result+n, 0);
		if (cnt) {
			cout << n - cnt << '\n';
			for (int i = 1; i < n+1; i++) {
				if (!result[i])
					cout << i << ' ';
			}
		}
		else
			cout << 0;
	}
	else {
		cout << "1\n1";
	}
}


#include <bits\stdc++.h>

using namespace std;

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

	int n;
	int a;
	int result[102] = {0};

	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a;
			if (a == -1 || !a)
				continue;

			if (a == 1)
				result[i+1]++;
			else if (a == 2)
				result[j+1]++;
			else {
				result[i+1]++;
				result[j+1]++;
			}
		}
	}
	int cnt = count (result+1, result+n, 0);
	if (cnt) {
		cout << cnt << '\n';
		for (int i = 1; i < n+1; i++) {
			if (!result[i])
				cout << i << ' ';
		}
	}
	else
		cout << 0;
}


#include <bits\stdc++.h>

using namespace std;

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

	int n;
	int a;
	int result[102] = {0};

	cin >> n;
	if (n > 1) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> a;
				if (a == -1 || !a)
					continue;

				if (a == 1)
					result[i+1]++;
				else if (a == 2)
					result[j+1]++;
				else {
					result[i+1]++;
					result[j+1]++;
				}
			}
		}

		int cnt = count (result+1, result+n, 0);
		if (cnt) {
			cout << n - cnt << '\n';
			for (int i = 1; i < n+1; i++) {
				if (!result[i])
					cout << i << ' ';
			}
		}
		else
			cout << 0;
	}
	else {
		cout << "1'n1";
	}
}


#include <bits\stdc++.h>

using namespace std;

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

	int n;
	int a;
	int result[102] = {0};

	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a;
			if (a == -1 || !a)
				continue;

			if (a == 1)
				result[i+1]++;
			else if (a == 2)
				result[j+1]++;
			else {
				result[i+1]++;
				result[j+1]++;
			}
		}
	}
	int cnt = count (result+1, result+n, 0);
	if (cnt) {
		cout << n - cnt << '\n';
		for (int i = 1; i < n+1; i++) {
			if (!result[i])
				cout << i << ' ';
		}
	}
	else
		cout << 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
int main()
{
    int n, d = 0;
    cin>>n;
    vector <int> my_vec;
    int a[n][n];
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            cin>>a[i][j];
    for (int i = 1; i <= n; i++)
        my_vec.push_back(i);
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (a[i][j] == 1 || a[i][j] == 3)
            {
                d++;
                my_vec.push_back(j);
                break;
            }
        }
    }
    sort(my_vec.begin(), my_vec.end());
    cout<<n - d<<endl;
    if (n - d != 0)
    {
        for (int i = 0; i < my_vec.size(); i++)
            if (count(my_vec.begin(), my_vec.end(), my_vec[i]) == 1)
                cout<<my_vec[i]<<endl;
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;
int main()
{
    int n, a, k = 0, i, j;
    cin>>n;
    vector <int> my_vec;
    for (i = 0; i < n; i++)
    {
        k = 0;
        for (j = 0; j < n; j++)
        {
            cin>>a;
            if (a == 1 || a == 3)
                k = 1;
        }
        if (k == 0)
            my_vec.push_back(i + 1);
    }
    cout<<my_vec.size()<<endl;
    for (int i = 0; i < my_vec.size(); i++)
        cout<<my_vec[i]<<" ";
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
int main()
{
    int n, d = 0, t = 0;
    cin>>n;
    vector <int> my_vec;
    int a[n][n];
    for (int i = 1; i <= n; i++)
        for (int j = 0; j < n; j++)
            cin>>a[i][j];
    for (int i = 1; i <= n; i++)
        my_vec.push_back(i);
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (a[i][j] == 1 || a[i][j] == 3)
            {
                d++;
                break;
            }
        }
        if (d > 0)
        {
            my_vec.push_back(i);
            d = 0;
            t++;
        }
    }
    sort(my_vec.begin(), my_vec.end());
    if (n - d != n)
    {
        cout<<t<<endl;
        for (int i = 0; i < my_vec.size(); i++)
            if (count(my_vec.begin(), my_vec.end(), my_vec[i]) == 1)
                cout<<my_vec[i]<<" ";
    }
    else
        cout<<0;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
int main()
{
    int n, d = 0;
    cin>>n;
    vector <int> my_vec;
    int a[n][n];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin>>a[i][j];
    for (int i = 0; i < n; i++)
        my_vec.push_back(i + 1);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (a[i][j] == 1 || a[i][j] == 3)
            {
                d++;
                my_vec.push_back(j);
                break;
            }
        }
    }
    cout<<n - d<<endl;
    if (n - d != 0)
    {
        for (int i = 0; i < my_vec.size(); i++)
            if (count(my_vec.begin(), my_vec.end(), my_vec[i]) == 1)
                cout<<my_vec[i]<<endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
int main()
{
    int n, d = 0, t = 0;
    cin>>n;
    vector <int> my_vec;
    int a[n][n];
    for (int i = 1; i <= n; i++)
        for (int j = 0; j < n; j++)
            cin>>a[i][j];
    for (int i = 1; i <= n; i++)
        my_vec.push_back(i);
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (a[i][j] == 1 || a[i][j] == 3)
            {
                d++;
                break;
            }
        }
        if (d > 0)
        {
            my_vec.push_back(i);
            t++;
            d = 0;
        }
    }
    sort(my_vec.begin(), my_vec.end());
    if (n - t != 0)
    {
        cout<<n - t<<endl;
        for (int i = 0; i < my_vec.size(); i++)
            if (count(my_vec.begin(), my_vec.end(), my_vec[i]) == 1)
                cout<<my_vec[i]<<" ";
    }
    else
        cout<<0;
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;
int main()
{
    int n, d = 0, t = 0;
    cin>>n;
    vector <int> my_vec;
    int a[n][n];
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            cin>>a[i][j];
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (a[i][j] == 1 || a[i][j] == 3)
                d++;
        }
        if (d == 0)
        {
            my_vec.push_back(i);
            t++;
        }
        d = 0;
    }

    cout<<t<<endl;
    if (n - d != 0)
    {
        for (int i = 0; i < my_vec.size(); i++)
                cout<<my_vec[i]<<endl;
    }
    return 0;
}


#include <algorithm>
#include <vector>

using namespace std;
int main()
{
    int n, d = 0, t = 0;
    cin>>n;
    vector <int> my_vec;
    int a[n][n];
    for (int i = 1; i <= n; i++)
        for (int j = 0; j < n; j++)
            cin>>a[i][j];
    for (int i = 1; i <= n; i++)
        my_vec.push_back(i);
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (a[i][j] == 1 || a[i][j] == 3)
            {
                d++;
                break;
            }
        }
        if (d > 0)
        {
            my_vec.push_back(i);
            t++;
            d = 0;
        }
    }
    sort(my_vec.begin(), my_vec.end());
    if (n - t != 0)
    {
        cout<<n - t<<endl;
        for (int i = 0; i < my_vec.size(); i++)
            if (count(my_vec.begin(), my_vec.end(), my_vec[i]) == 1)
                cout<<my_vec[i]<<" ";
    }
    else
        cout<<0;
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;
int main()
{
    int n, d = 0, t = 0;
    cin>>n;
    vector <int> my_vec;
    int a[n][n];
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            cin>>a[i][j];
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (a[i][j] == 1 || a[i][j] == 3)
                d++;
        }
        if (d == 0)
        {
            my_vec.push_back(i);
            t++;
        }
        d = 0;
    }
    cout<<t<<endl;
    if (n - d != 0)
    {
        for (int i = 0; i < my_vec.size(); i++)
                cout<<my_vec[i]<<endl;
    }
    return 0;
}


#include <algorithm>
#include <vector>

using namespace std;
int main()
{
    int n, d = 0, t = 0;
    cin>>n;
    vector <int> my_vec;
    int a[n][n];
    for (int i = 1; i <= n; i++)
        for (int j = 0; j < n; j++)
            cin>>a[i][j];
    for (int i = 1; i <= n; i++)
        my_vec.push_back(i);
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (a[i][j] == 1 || a[i][j] == 3)
            {
                d++;
                break;
            }
        }
        if (d > 0)
        {
            my_vec.push_back(i);
            t++;
            d = 0;
        }
    }
    sort(my_vec.begin(), my_vec.end());
    if (n - t != n)
    {
        cout<<n - t<<endl;
        for (int i = 0; i < my_vec.size(); i++)
            if (count(my_vec.begin(), my_vec.end(), my_vec[i]) == 1)
                cout<<my_vec[i]<<" ";
    }
    else
        cout<<0;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
int main()
{
    int n, d = 0, t = 0;
    cin>>n;
    vector <int> my_vec;
    int a[n][n];
    for (int i = 1; i <= n; i++)
        for (int j = 0; j < n; j++)
            cin>>a[i][j];
    for (int i = 1; i <= n; i++)
        my_vec.push_back(i);
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (a[i][j] == 1 || a[i][j] == 3)
            {
                d++;
                break;
            }
        }
        if (d > 0)
        {
            my_vec.push_back(i);
            t++;
            d = 0;
        }
    }
    sort(my_vec.begin(), my_vec.end());
    if (n - t != n)
    {
        cout<<n - t<<endl;
        for (int i = 0; i < my_vec.size(); i++)
            if (count(my_vec.begin(), my_vec.end(), my_vec[i]) == 1)
                cout<<my_vec[i]<<" ";
    }
    else
        cout<<0;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
int main()
{
    int n, d = 0;
    cin>>n;
    vector <int> my_vec;
    int a[n][n];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin>>a[i][j];
    for (int i = 1; i <= n; i++)
        my_vec.push_back(i);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (a[i][j] == 1 || a[i][j] == 3)
            {
                d++;
                my_vec.push_back(j);
                break;
            }
        }
    }
    sort(my_vec.begin(), my_vec.end());
    cout<<n - d<<endl;
    if (n - d != 0)
    {
        for (int i = 0; i < my_vec.size(); i++)
            if (count(my_vec.begin(), my_vec.end(), my_vec[i]) == 1)
                cout<<my_vec[i]<<" ";
    }
    return 0;
}


#include <iostream>
using namespace std;
int a[1000][1000];
int main(){
    int n = 0,tmp = 0,b[1000];
    cin >> n;
    for(int i = 1; i <= n; i++){
        int m = 0;
        for(int j = 1; j <= n; j++){
            cin >> a[i][j];
        }
    }
    for(int i = 1; i <= n; i++){
        int flag = 0;
        for(int j = 1; j <= n; j++){
            if(a[i][j] == 1 || a[i][j] == 3) {
                flag = 1;
            }
        }
        if(flag == 1){
            continue;
        }else {
            tmp++;
            b[i] = i;
        }

    }
    cout << tmp << endl;
    for(int i = 1; i <= n; i++){
        if(b[i] != 0){
            cout << b[i] << " ";
        }
    }
    cout << endl;
    return 0;
}


#include<bits/stdc++.h>
bool used[100];
using namespace std;
    main(){
        ios::sync_with_stdio(0);
    int n;
    cin >> n;
    int a[n][n];
    for(int i = 1 ; i <= n ;i++){
        for(int j = 1 ; j <= n ;j++){
            cin >> a[i][j];
        }
    }
    for(int i = 1 ; i <= n ;i++){
        for(int j = 1 ; j <= n ;j++){
            if(a[i][j]==1){
                used[i] = 1;
            }
           else if(a[i][j]==2){
                used[j] = 1;
            }
           else if(a[i][j]==3){
                used[i] = 1;
                used[j] = 1;
            }
        }
    }

    vector<int > ans;
    for(int i = 1 ; i <= n ;i++){
       if(!used[i])ans.push_back(i);
    }
    cout << ans.size() << endl;
    for(int i = 0 ; i < ans.size();i++)
        cout << ans[i] <<" ";

    }


#include<bits/stdc++.h>
bool used[100];
using namespace std;
    main(){
        ios::sync_with_stdio(0);
    int n;
    cin >> n;
    int a[n][n];
    for(int i = 1 ; i <= n ;i++){
        for(int j = 1 ; j <= n ;j++){
            cin >> a[i][j];
        }
    }
    for(int i = 1 ; i <= n ;i++){
        for(int j = 1 ; j <= n ;j++){
            if(a[i][j]==1){
                used[i] = 1;
            }
           else if(a[i][j]==2){
                used[j] = 1;
            }
           else if(a[i][j]==3){
                used[i] = 1;
                used[j] = 1;
            }
        }
    }
    int ans = 0;
    for(int i = 1 ; i <= n ;i++){
        if(!used[i])ans++;
    }
    cout << ans << endl;
    for(int i = 1 ; i <= n ;i++){
       if(!used[i])
        cout << i <<" ";
    }

    }


#include<bits/stdc++.h>
bool used[1001];
int a[1001][1001];
using namespace std;
    main(){
    int n;
    cin >> n;

    for(int i = 1 ; i <= n ;i++){
        for(int j = 1 ; j <= n ;j++){
            cin >> a[i][j];
        }
    }
    for(int i = 1 ; i <= n ;i++){
        for(int j = 1 ; j <= n ;j++){
            if(a[i][j]==1){
                used[i] = 1;
            }
           else if(a[i][j]==2){
                used[j] = 1;
            }
           else if(a[i][j]==3){
                used[i] = 1;
                used[j] = 1;
            }
        }
    }

    vector<int > ans;
    for(int i = 1 ; i <= n ;i++){
       if(!used[i])ans.push_back(i);
    }
    cout << ans.size() << endl;
    for(int i = 0 ; i < ans.size();i++)
        cout << ans[i] <<" ";

    }


#include<bits/stdc++.h>
bool used[100];
using namespace std;
    main(){
    int n;
    cin >> n;
    int a[n][n];
    for(int i = 1 ; i <= n ;i++){
        for(int j = 1 ; j <= n ;j++){
            cin >> a[i][j];
        }
    }
    for(int i = 1 ; i <= n ;i++){
        for(int j = 1 ; j <= n ;j++){
            if(a[i][j]==1){
                used[i] = 1;
            }
            if(a[i][j]==2){
                used[j] = 1;
            }
            if(a[i][j]==3){
                used[i] = 1;
                used[j] = 1;
            }
        }
    }
    int ans = 0;
    for(int i = 1 ; i <= n ;i++){
        if(!used[i])ans++;
    }
    cout << ans << endl;
    for(int i = 1 ; i <= n ;i++){
        if(!used[i])cout <<i<<" ";
    }

    }