#include<bits/stdc++.h>
#define i64 long long
using namespace std;
int t,n,a[100001];
int c[100001];
int k,l,x,m;
map <int,int> mp;
void doit ()
{
	scanf("%lld",&n);
	for (int i=1;i<=n;i++)
	scanf("%lld",&a[i]);
	m=0;
	mp.clear();
	for (int i=1;i<=n;i++)
	mp[a[i]]++;
	for (map<int,int>::iterator i=mp.begin();i!=mp.end();i++)
	{
		k=(*i).second;
		l=(*i).first;
		if (k>=2) c[++m]=l;
		if (k>=4)
		{
			printf("%d %d %d %d\n",l,l,l,l);
			return;
		}
	}
	i64 x=0,y=0;
	for (int i=2;i<=m;i++)
	{
		i64 xx=c[i-1],yy=c[i];
		if (x==0 && y==0) x=xx,y=yy;
			else if ((xx*xx+yy*yy)*x*y<(x*x+y*y)*xx*yy) x=xx,y=yy;
	}
	printf("%lld %lld %lld %lld\n",x,x,y,y);
	return;
};
int main()
{
	scanf("%d",&t);
	while (t--)
	doit();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int t,n,a[100001];
double ans,x;
int k,l;
void doit ()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	int last=0;
	ans=1e+38;
	k=0;
	l=0;
	for (int i=1,j=1;i<=n;i=j)
	{
		while (a[i]==a[j])
		j++;
		if (i==j-1) continue;
		if (i<=j-4)
		{
			printf("%d %d %d %d\n",a[i],a[i],a[i],a[i]);
			return;
		}
		if (last)
		{
			if (ans>(a[i]+last)*(a[i]+last)*4.0/(a[i]*last))
			{
				ans=(a[i]+last)*(a[i]+last)*4.0/(a[i]*last);
				k=last;
				l=i;
			}
		}
		last=a[i];
	}
	printf("%d %d %d %d\n",a[k],a[k],a[l],a[l]);
	return;
};
int main()
{
	scanf("%d",&t);
	while (t--)
	doit();
}


#include<bits/stdc++.h>
#define i64 long long
using namespace std;
int t,n,a[100001];
int c[100001];
int k,l,x,m;
map <int,int> mp;
void doit ()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	m=0;
	mp.clear();
	for (int i=1;i<=n;i++)
	mp[a[i]]++;
	for (map<int,int>::iterator i=mp.begin();i!=mp.end();i++)
	{
		k=(*i).second;
		l=(*i).first;
		if (k>=2) c[++m]=l;
		if (k>=4)
		{
			printf("%d %d %d %d\n",l,l,l,l);
			return;
		}
	}
	i64 x=0,y=0;
	for (int i=2;i<=m;i++)
	{
		i64 xx=c[i-1],yy=c[i];
		if (x==0 && y==0) x=xx,y=yy;
			else if ((xx*xx+yy*yy)*x*y<(x*x+y*y)*xx*yy) x=xx,y=yy;
	}
	printf("%lld %lld %lld %lld\n",x,x,y,y);
	return;
};
int main()
{
	scanf("%d",&t);
	while (t--)
	doit();
	return 0;
}


#include<bits/stdc++.h>
#define i64 long long
using namespace std;
i64 t,n,a[100001];
i64 c[100001];
i64 k,l,x,m;
map <i64,i64> mp;
void doit ()
{
	scanf("%lld",&n);
	for (i64 i=1;i<=n;i++)
	scanf("%lld",&a[i]);
	m=0;
	mp.clear();
	for (i64 i=1;i<=n;i++)
	{
		if (mp[a[i]]) c[++m]=a[i];
		mp[a[i]]++;
		if (mp[a[i]]==4)
		{
			printf("%lld %lld %lld %lld\n",a[i],a[i],a[i],a[i]);
			return;
		}
	}
	sort(c+1,c+1+m);
	k=l=0;
	for (i64 i=2;i<=m;i++)
	{
		if (k==0 && l==0) k=c[i-1],l=c[i];
			else
		{
			i64 x=c[i-1],y=c[i];
			if ((x*x+y*y)*k*l<(k*k+l*l)*x*y) k=x,l=y;
		}
	}
	printf("%lld %lld %lld %lld\n",k,k,l,l);
	return;
};
int main()
{
	scanf("%d",&t);
	while (t--)
	doit();
	return 0;
}


#include<bits/stdc++.h>
#define i64 long long
using namespace std;
i64 t,n,a[100001];
i64 c[100001];
i64 k,l,x,m;
map <i64,i64> mp;
void doit ()
{
	scanf("%lld",&n);
	for (i64 i=1;i<=n;i++)
	scanf("%lld",&a[i]);
	m=0;
	mp.clear();
	for (i64 i=1;i<=n;i++)
	{
		if (mp[a[i]]==4)
		{
			printf("%lld %lld %lld %lld\n",a[i],a[i],a[i],a[i]);
			return;
		}
		if (mp[a[i]]) c[++m]=a[i];
		mp[a[i]]++;
	}
	sort(c+1,c+1+m);
	k=l=0;
	for (int i=2;i<=m;i++)
	{
		if (k==0 && l==0) k=c[i-1],l=c[i];
			else
		{
			i64 x=c[i-1],y=c[i];
			if ((x*x+y*y)*k*l<(k*k+l*l)*x*y) k=x,l=y;
		}
	}
	printf("%lld %lld %lld %lld\n",k,k,l,l);
	return;
};
int main()
{
	scanf("%d",&t);
	while (t--)
	doit();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int t,n,a[100001];
double ans,x;
int k,l;
void doit ()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	int last=0;
	ans=1e+38;
	k=0;
	l=0;
	for (int i=1,j=1;i<=n;i=j)
	{
		while (a[i]==a[j])
		j++;
		if (i>=j-1) continue;
		if (i<=j-4)
		{
			ans=16;
			k=l=i;
		}
		if (last)
		{
			if (ans>(a[i]+a[last])*(a[i]+a[last])*4.0/(a[i]*a[last]))
			{
				ans=(a[i]+a[last])*(a[i]+a[last])*4.0/(a[i]*a[last]);
				k=last;
				l=i;
			}
		}
		last=i;
	}
	printf("%0.5lf\n",ans);
	printf("%d %d %d %d\n",a[k],a[k],a[l],a[l]);
	return;
};
int main()
{
	scanf("%d",&t);
	while (t--)
	doit();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int t,n,a[100001];
double ans;
int k,l,x;
void doit ()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	ans=1e+38;
	k=l=x=0;
	for (int i=1,j=1;i<=n;i=j)
	{
		while (a[i]==a[j])
		j++;
		if (i>=j-1) continue;
		if (i<=j-4)
		{
			ans=16;
			k=l=i;
		}
		if (x)
		{
			if (ans>(a[i]+a[x])*(a[i]+a[x])*4.0/(a[i]*a[x]))
			{
				ans=(a[i]+a[x])*(a[i]+a[x])*4.0/(a[i]*a[x]);
				k=x;
				l=i;
			}
		}
		x=i;
	}
	//printf("%0.5lf\n",ans);
	printf("%d %d %d %d\n",a[k],a[k],a[l],a[l]);
	return;
};
int main()
{
	scanf("%d",&t);
	while (t--)
	doit();
	return 0;
}


#include<bits/stdc++.h>
#define i64 long long
using namespace std;
int t,n,a[100001];
int c[100001];
int k,l,x,m;
map <int,int> mp;
void doit ()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	m=0;
	mp.clear();
	for (int i=1;i<=n;i++)
	mp[a[i]]++;
	for (map<int,int>::iterator it=mp.begin();it!=mp.end();it++)
	{
		k=(*it).second;
		l=(*it).first;
		if (k>=2) c[++m]=l;
		if (k>=4)
		{
			printf("%d %d %d %d\n",l,l,l,l);
			return;
		}
	}
	i64 x=0,y=0;
	for (int i=2;i<=m;i++)
	{
		i64 xx=c[i-1],yy=c[i];
		if (x==0 && y==0) x=xx,y=yy;
			else if ((xx*xx+yy*yy)*x*y<(x*x+y*y)*xx*yy) x=xx,y=yy;
	}
	printf("%lld %lld %lld %lld\n",x,x,y,y);
	return;
};
int main()
{
	scanf("%d",&t);
	while (t--)
	doit();
	return 0;
}


#include<bits/stdc++.h>
#define i64 long long
using namespace std;
int n,x;
map<int,int> mp;
int a[500001],m;
void mian ()
{
	scanf("%d",&n);
	mp.clear();
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		mp[x]++;
	}
	m=0;
	for (map<int,int>::iterator it=mp.begin();it!=mp.end();it++)
	{
		int fi=(*it).first;
		int se=(*it).second;
		if (se>=2) a[++m]=fi;
		if (se>=4)
		{
			printf("%d %d %d %d\n",fi,fi,fi,fi);
			return;
		}
	}
	i64 x=0,y=0;
	for (int i=2;i<=m;i++)
	{
		i64 xx=a[i-1],yy=a[i];
		if (x==0 && y==0) x=xx,y=yy;
			else if ((x*x+y*y)*xx*yy>(xx*xx+yy*yy)*x*y) x=xx,y=yy;
	}
	printf("%lld %lld %lld %lld\n",x,x,y,y);
	return;
}
int main()
{
	int T;
	scanf("%d",&T);
	while (T--)
	mian();
	return 0;
}


#include<bits/stdc++.h>
#define i64 long long
using namespace std;
i64 t,n,a[100001];
i64 c[100001];
i64 k,l,x,m;
map <i64,i64> mp;
void doit ()
{
	scanf("%lld",&n);
	for (i64 i=1;i<=n;i++)
	scanf("%lld",&a[i]);
	m=0;
	mp.clear();
	for (i64 i=1;i<=n;i++)
	mp[a[i]]++;
	for (map<i64,i64>::iterator i=mp.begin();i!=mp.end();i++)
	{
		k=(*i).second;
		l=(*i).first;
		if (k>=2) c[++m]=l;
		if (k>=4)
		{
			printf("%lld %lld %lld %lld\n",l,l,l,l);
			return;
		}
	}
	k=l=0;
	for (i64 i=2;i<=m;i++)
	{
		if (k==0 && l==0) k=c[i-1],l=c[i];
			else
		{
			i64 x=c[i-1],y=c[i];
			if ((x*x+y*y)*k*l<(k*k+l*l)*x*y) k=x,l=y;
		}
	}
	printf("%lld %lld %lld %lld\n",k,k,l,l);
	return;
};
int main()
{
	scanf("%d",&t);
	while (t--)
	doit();
	return 0;
}


#include<bits/stdc++.h>
#define i64 long long
using namespace std;
i64 t,n,a[100001];
i64 c[100001];
i64 k,l,x,m;
map <i64,i64> mp;
void doit ()
{
	scanf("%lld",&n);
	for (i64 i=1;i<=n;i++)
	scanf("%lld",&a[i]);
	m=0;
	for (i64 i=1;i<=n;i++)
	{
		if (mp[a[i]]==4)
		{
			printf("%lld %lld %lld %lld\n",a[i],a[i],a[i],a[i]);
			return;
		}
		if (mp[a[i]]) c[++m]=a[i];
		mp[a[i]]++;
	}
	sort(c+1,c+1+m);
	k=l=0;
	for (int i=2;i<=m;i++)
	{
		if (k==0 && l==0) k=c[i-1],l=c[i];
			else
		{
			i64 x=c[i-1],y=c[i];
			if ((x*x+y*y)*k*l<(k*k+l*l)*x*y) k=x,l=y;
		}
	}
	printf("%lld %lld %lld %lld\n",k,k,l,l);
	return;
};
int main()
{
	scanf("%d",&t);
	while (t--)
	doit();
	return 0;
}


#include<bits/stdc++.h>
#define i64 long long
using namespace std;
i64 t,n,a[100001];
i64 c[100001];
i64 k,l,x,m;
map <i64,i64> mp;
void doit ()
{
	scanf("%lld",&n);
	for (i64 i=1;i<=n;i++)
	scanf("%lld",&a[i]);
	m=0;
	for (i64 i=1;i<=n;i++)
	{
		if (mp[a[i]]==4)
		{
			printf("%lld %lld %lld %lld\n",a[i],a[i],a[i],a[i]);
			return;
		}
		if (mp[a[i]]) c[++m]=a[i],mp[a[i]]++;
			else mp[a[i]]++;
	}
	sort(c+1,c+1+m);
	k=l=0;
	for (int i=2;i<=m;i++)
	{
		if (k==0 && l==0) k=c[i-1],l=c[i];
			else
		{
			i64 x=c[i-1],y=c[i];
			if ((x*x+y*y)*k*l<(k*k+l*l)*x*y) x=k,y=l;
		}
	}
	printf("%lld %lld %lld %lld\n",k,k,l,l);
	return;
};
int main()
{
	scanf("%d",&t);
	while (t--)
	doit();
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stack>
//#include <bits/stdc++.h>

using namespace std;

int main()
{
    //freopen("1.txt","r",stdin);
    long long n,m,a,b,t,j;
    double y,q;
    long long sum=0;
    cin>>t;
    for(int i=1;i<=t;++i)
    {
        cin>>n;
        vector<int> vv(n);
        for(int u=0;u<n;++u)
            cin>>vv[u];
        sort(vv.begin(),vv.end());

         q=-1;
        double mi=-1000000000;

         for(int u=0;u<n;u=j)
         {
//cout<<j<<"   ";
if(mi==1) break;
              y=q;

             q=vv[u];
             j=u;
             while(vv[j]==q)
             {
                 ++j;
             }
             //cout<<setprecision(20)<<(2*y+2*q)*(2*y+2*q)/(y*q)<<" "<<y<<" "<<q<<" "<<"\n";
            // cout<<y<<" "<<q<<" "<<u<<" "<<j<<" "<<"\n";
             if(j-u<2) {q=y; continue;}

             if(y!=-1)
            {if(mi<y/q)
            {
                mi=y/q;
                a=y;b=q;
            }}
             if(j-u>=4)
             {
                 y=q;
                 //cout<<mi<<" "<<(2*y+2*q)*(2*y+2*q)/(y*q)<<"---------\n";
                  if(mi<(y/q))
            {
                mi=(y/q);
                a=y;b=q;
            }
             }

         }

cout<<a<<" "<<a<<" "<<b<<" "<<b<<"\n";

    }

return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <map>
//#include <bits/stdc++.h>

using namespace std;

int main()
{
    //freopen("1.txt","r",stdin);
    long long n,m,a,b,t,j;
    double y,q;
    long long sum=0;
    map<int,int>mm;
    cin>>t;
    for(int i=1;i<=t;++i)
    {
        cin>>n;
        vector<int> vv;
        mm.clear();
        int x;
        for(int u=0;u<n;++u)
            {
                cin>>x;
                //vv[x]++;
                mm[x]++;

            }
        //sort(vv.begin(),vv.end());

         q=-1;
        double mi=-1000000000;
         for(auto it=mm.begin();it!=mm.end();it++)
         {
             y=q;
             if(mi==1) break;
             if(it->second<2)
             {
                 q=y; continue;
             }
             q= it->first;
             if(it->second>=4)
             y=it->first;

             if(mi<y/q)
            {
                mi=y/q;
                a=y;b=q;
            }

         }

/*
        q=vv[0];
         for(int u=1;u<vv.size();u++)
         {
//cout<<j<<"   ";

              y=q;
              q=vv[u];

                          //cout<<setprecision(20)<<(2*y+2*q)*(2*y+2*q)/(y*q)<<" "<<y<<" "<<q<<" "<<"\n";
            // cout<<y<<" "<<q<<" "<<u<<" "<<j<<" "<<"\n";

            {if(mi<y/q)
            {
                mi=y/q;
                a=y;b=q;
            }}

         }

*/
cout<<a<<" "<<a<<" "<<b<<" "<<b<<"\n";

    }

return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stack>
//#include <bits/stdc++.h>

using namespace std;

int main()
{
    //freopen("1.txt","r",stdin);
     //freopen("2.txt","w",stdout);
    int n,m,a,b,t,j;
    int y,q;
    //long long sum=0;
    cin>>t;
    for(int i=1;i<=t;++i)
    {
         a=0;b=1;
        scanf("%d",&n);
        vector<int> vv(n);
        for(int u=0;u<n;++u)
            scanf("%d",&vv[u]);
        sort(vv.begin(),vv.end());

         q=-1;
        //double mi=-1000000000;

         for(int u=0;u<n;u=j)
         {
//cout<<j<<"   ";
//if(mi==1) break;
              y=q;

             q=vv[u];
             j=u;
             while(j<n && vv[j]==q)
             {
                 ++j;
             }
             //cout<<setprecision(20)<<(2*y+2*q)*(2*y+2*q)/(y*q)<<" "<<y<<" "<<q<<" "<<"\n";
            // cout<<y<<" "<<q<<" "<<u<<" "<<j<<" "<<"\n";
             if(j-u<2) {q=y; continue;}

             if(y!=-1)
             if((1.0*a/b<1.0*y/q))
            {

                a=y;b=q;
            }
             if(j-u>=4)
             {
                 y=q;
                 //cout<<mi<<" "<<(2*y+2*q)*(2*y+2*q)/(y*q)<<"---------\n";

                a=y;b=q;

             }

         }

printf("%d %d %d %d\n",a,a,b,b);

    }

return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <map>
//#include <bits/stdc++.h>

using namespace std;

int main()
{
    //freopen("1.txt","r",stdin);
    // freopen("2.txt","w",stdout);
    int n,m,a=0,b=1,t,j;
    int y,q,x;

    cin>>t;
    for(int i=1;i<=t;++i)
    {
        a=0;b=1;
      scanf("%d",&n);
    vector<int> vv;
         map<int,int>mm;

        for(int u=0;u<n;++u)
            {
                scanf("%d",&x);
                //vv[x]++;
                mm[x]++;
if(mm[x]>=2)
{
    vv.push_back(x);
    mm[x]=0;
}
            }
        //sort(vv.begin(),vv.end());

        sort(vv.begin(),vv.end());
        //double mi=-1000000000;
        q=vv[0];

         for(int u=1;u<vv.size();++u)
         {
             y=q;
             q=vv[u];
             //if(mi==1) break;

             if((1.0*a/b<1.0*y/q))
            {

                a=y;b=q;
            }

         }

/*
        q=vv[0];
         for(int u=1;u<vv.size();u++)
         {
//cout<<j<<"   ";

              y=q;
              q=vv[u];

                          //cout<<setprecision(20)<<(2*y+2*q)*(2*y+2*q)/(y*q)<<" "<<y<<" "<<q<<" "<<"\n";
            // cout<<y<<" "<<q<<" "<<u<<" "<<j<<" "<<"\n";

            {if(mi<y/q)
            {
                mi=y/q;
                a=y;b=q;
            }}

         }

*/
//cout<<a<<" "<<a<<" "<<b<<" "<<b<<"\n";
 printf("%d %d %d %d\n",a,a,b,b);

    }

return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stack>
//#include <bits/stdc++.h>

using namespace std;

int main()
{
    //freopen("1.txt","r",stdin);
    long long n,m,a,b,t,j;
    double y,q;
    long long sum=0;
    cin>>t;
    for(int i=1;i<=t;++i)
    {
        cin>>n;
        vector<int> vv(10001);
        int x;
        for(int u=0;u<n;++u)
            {
                cin>>x;
                vv[x]++;

            }
        //sort(vv.begin(),vv.end());

         q=-1;
        double mi=-1000000000;

         for(int u=1;u<=10000;u++)
         {
//cout<<j<<"   ";
//if(mi==1) break;
              y=q;
              if(vv[u]>=2)
             q=u;
             else
                {
                    q=y; continue;
                }

                          //cout<<setprecision(20)<<(2*y+2*q)*(2*y+2*q)/(y*q)<<" "<<y<<" "<<q<<" "<<"\n";
            // cout<<y<<" "<<q<<" "<<u<<" "<<j<<" "<<"\n";

             if(y!=-1)
            {if(mi<y/q)
            {
                mi=y/q;
                a=y;b=q;
            }}
             if(vv[u]>=4)
             {
                 y=q;
             mi=1;
              a=y;b=q;
             break;
             }

         }

cout<<a<<" "<<a<<" "<<b<<" "<<b<<"\n";

    }

return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <map>
//#include <bits/stdc++.h>

using namespace std;

int main()
{
    //freopen("1.txt","r",stdin);
    long long n,m,a,b,t,j;
    double y,q;
    long long sum=0;
    cin>>t;
    for(int i=1;i<=t;++i)
    {
        cin>>n;
        vector<int> vv;
        map<int,int>mm;
        int x;
        for(int u=0;u<n;++u)
            {
                cin>>x;
                //vv[x]++;
                mm[x]++;

            }
        //sort(vv.begin(),vv.end());

         q=-1;
        double mi=-1000000000;
         for(auto it=mm.begin();it!=mm.end();it++)
         {
             if(it->second>=2)
             vv.push_back(it->first);
             if(it->second>=4)
             vv.push_back(it->first);

         }

        q=vv[0];
         for(int u=1;u<vv.size();u++)
         {
//cout<<j<<"   ";
if(mi==1) break;
              y=q;
              q=vv[u];

                          //cout<<setprecision(20)<<(2*y+2*q)*(2*y+2*q)/(y*q)<<" "<<y<<" "<<q<<" "<<"\n";
            // cout<<y<<" "<<q<<" "<<u<<" "<<j<<" "<<"\n";

            {if(mi<y/q)
            {
                mi=y/q;
                a=y;b=q;
            }}

         }

cout<<a<<" "<<a<<" "<<b<<" "<<b<<"\n";

    }

return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <map>
//#include <bits/stdc++.h>

using namespace std;

int main()
{
    //freopen("1.txt","r",stdin);
    // freopen("2.txt","w",stdout);
    int n,m,a,b,t,j;
    int y,q,x;

    cin>>t;
    for(int i=1;i<=t;++i)
    {
      scanf("%d",&n);
    vector<int> vv;
         map<int,int>mm;

        for(int u=0;u<n;++u)
            {
                scanf("%d",&x);
                //vv[x]++;
                mm[x]++;
if(mm[x]>=2)
{
    vv.push_back(x);
    mm[x]=0;
}
            }
        //sort(vv.begin(),vv.end());

        sort(vv.begin(),vv.end());
        //double mi=-1000000000;
        q=vv[0];

         for(int u=1;u<vv.size();++u)
         {
             y=q;
             q=vv[u];
             //if(mi==1) break;

             if((1.0*a/b<1.0*y/q))
            {

                a=y;b=q;
            }

         }

/*
        q=vv[0];
         for(int u=1;u<vv.size();u++)
         {
//cout<<j<<"   ";

              y=q;
              q=vv[u];

                          //cout<<setprecision(20)<<(2*y+2*q)*(2*y+2*q)/(y*q)<<" "<<y<<" "<<q<<" "<<"\n";
            // cout<<y<<" "<<q<<" "<<u<<" "<<j<<" "<<"\n";

            {if(mi<y/q)
            {
                mi=y/q;
                a=y;b=q;
            }}

         }

*/
//cout<<a<<" "<<a<<" "<<b<<" "<<b<<"\n";
 printf("%d %d %d %d\n",a,a,b,b);

    }

return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <map>
//#include <bits/stdc++.h>

using namespace std;

int main()
{
    //freopen("1.txt","r",stdin);
    long long n,m,a,b,t,j;
    double y,q;
    long long sum=0;
    map<int,int>mm;
    cin>>t;
    for(int i=1;i<=t;++i)
    {
        cin>>n;
        vector<int> vv;
        mm.clear();
        int x;
        for(int u=0;u<n;++u)
            {
                cin>>x;
                //vv[x]++;
                mm[x]++;

            }
        //sort(vv.begin(),vv.end());

         q=-1;
        double mi=-1000000000;
         for(auto it=mm.begin();it!=mm.end();it++)
         {
             if(it->second>=2)
             vv.push_back(it->first);
             if(it->second>=4)
             vv.push_back(it->first);

         }

        q=vv[0];
         for(int u=1;u<vv.size();u++)
         {
//cout<<j<<"   ";
if(mi==1) break;
              y=q;
              q=vv[u];

                          //cout<<setprecision(20)<<(2*y+2*q)*(2*y+2*q)/(y*q)<<" "<<y<<" "<<q<<" "<<"\n";
            // cout<<y<<" "<<q<<" "<<u<<" "<<j<<" "<<"\n";

            {if(mi<y/q)
            {
                mi=y/q;
                a=y;b=q;
            }}

         }

cout<<a<<" "<<a<<" "<<b<<" "<<b<<"\n";

    }

return 0;
}


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

const int N = 755, L = 1e7 + 9;
bool reach[N][N];
struct AhoCorasick {
    int link[L], sz, to[L][2], dp[L][2], term[L], last[L];
    AhoCorasick() {
        memset(link, 0, sizeof link);
        memset(to, 0, sizeof to);
        memset(dp, -1, sizeof dp);
        memset(term, 0, sizeof term);
        memset(last, 0, sizeof last);
        sz = 1;
    }
    void insert(string &s, int id) {
        int u = 0;
        for (char c: s) {
            if (!to[u][c - 'a']) to[u][c - 'a'] = sz++;
            u = to[u][c - 'a'];
        }
        term[u] = id;
    }
    void push_links() {
        queue<int> q;
        q.push(0); link[0] = -1;
        while (!q.empty()) {
            int u = q.front(); q.pop();
            for (int c = 0; c < 2; c++) {
                int v = to[u][c];
                if (!v) continue;
                int j = link[u];
                while (j != -1 && !to[j][c]) j = link[j];
                if (j != -1) link[v] = to[j][c];
                else link[v] = 0;
                if (!term[link[v]]) last[v] = last[link[v]];
                else last[v] = link[v];
                q.push(v);
            }
        }
    }
    int go(int v, char ch) {
    	int c = ch - 'a';
        if (dp[v][c] == -1) {
            if (to[v][c]) return dp[v][c] = to[v][c];
            return dp[v][c] = (v == 0 ? 0 : go(link[v], ch));
        }
        return dp[v][c];
    }
    void traverse(string &s, int id) {
        int n = s.size(), cur = 0;
        for (int i = 0; i < n; i++) {
            cur = go(cur, s[i]);
            if (term[cur] && term[cur] != id) reach[term[cur]][id] = 1;
            else reach[term[last[cur]]][id] = 1;
        }
    }
} t;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
struct Kuhn {
	int n; vector<vector<int>> g;
	vector<int> l, r; vector<bool> vis;
	Kuhn() {}
	Kuhn(int _n, int _m) {
		n = _n;
		g.resize(n + 1); vis.resize(n + 1, false);
		l.resize(n + 1, -1); r.resize(_m + 1, -1);
	}
	void add_edge(int a, int b) {
		g[a].push_back(b);
	}
	bool yo(int u) {
		if (vis[u])  return false;
		vis[u] = true;
		for (auto v : g[u]) {
			if (r[v] == -1 || yo(r[v])) {
				l[u] = v;
				r[v] = u;
				return true;
			}
		}
		return false;
	}
	int maximum_matching() {
		//for (int i = 1; i <= n; i++) shuffle(g[i].begin(), g[i].end(), rnd);
		vector<int> p(n); iota(p.begin(), p.end(), 1);
		//shuffle(p.begin(), p.end(), rnd);
		bool ok = true;
		while (ok) {
			ok = false;
			vis.assign(n + 1, false);
			for (auto &i: p) if(l[i] == -1) ok |= yo(i);
		}
		int ans = 0;
		for (int i = 1; i <= n; i++) ans += l[i] != -1;
		return ans;
	}
}M;
bool vis[N][2];
vector<int> g[N]; bool vc[N];
void dfs(int u, int side) {
	if (vis[u][side]) return;
	vis[u][side] = 1;
	if (side == 0) {
		for (auto v: g[u]) {
			dfs(v, 1);
		}
	}
	else dfs(M.r[u], 0);
}
string s[N]; //it assumes all strings are distinct
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    for (int i = 1; i <= n; i++) {
    	cin >> s[i];
    	t.insert(s[i], i);
    }
    t.push_links();
    for (int i = 1; i <= n; i++) t.traverse(s[i], i);
    M = Kuhn(n, n);
    for (int i = 1; i <= n; i++) {
    	for (int j = 1; j <= n; j++) {
    		if (reach[i][j]) {
    			M.add_edge(i, j);
    			g[i].push_back(j);
    		}
    	}
    }
    int p = M.maximum_matching();
    for (int i = 1; i <= n; i++) if (M.l[i] == -1) dfs(i, 0);
	for (int i = 1; i <= n; i++) {
		if (!vis[i][0] || vis[i][1]) vc[i] = 1;
	}
	cout << n - p << '\n';
	for (int i = 1; i <= n; i++) {
		if (!vc[i]) cout << i << ' ';
	}
	cout << '\n';
    return 0;
}


// CF590E.cpp
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1550, INF = 0x3f3f3f3f, MAX_S = 1e7 + 200;

int n, start_pos, end_pos, head[MAX_N], current, dep[MAX_N], cur[MAX_N], ptot = 1;
int ch[MAX_N][2], fail[MAX_N], tag[MAX_N], pos[MAX_N], fa[MAX_N];
bool mp[MAX_N][MAX_N];
char str[MAX_S];

struct edge
{
    int to, nxt, weight;
} edges[MAX_N * MAX_N];

void addpath(int src, int dst, int weight)
{
    edges[current].to = dst, edges[current].nxt = head[src];
    edges[current].weight = weight, head[src] = current++;
}

void addtube(int src, int dst, int weight)
{
    addpath(src, dst, weight);
    addpath(dst, src, 0);
}

bool bfs()
{
    memset(dep, 0, sizeof(dep));
    queue<int> q;
    q.push(start_pos), dep[start_pos] = 1;
    while (!q.empty())
    {
        int u = q.front();
        q.pop();
        for (int i = head[u]; i != -1; i = edges[i].nxt)
            if (edges[i].weight > 0 && dep[edges[i].to] == 0)
                dep[edges[i].to] = dep[u] + 1, q.push(edges[i].to);
    }
    return dep[end_pos] != 0;
}

int dfs(int u, int flow)
{
    if (u == end_pos || flow == 0)
        return flow;
    for (int &i = cur[u]; i != -1; i = edges[i].nxt)
        if (edges[i].weight > 0 && dep[edges[i].to] == dep[u] + 1)
            if (int di = dfs(edges[i].to, min(flow, edges[i].weight)))
            {
                edges[i].weight -= di, edges[i ^ 1].weight += di;
                return di;
            }
    return 0;
}

int dinic()
{
    int ret = 0;
    while (bfs())
    {
        memcpy(cur, head, sizeof(cur));
        while (int di = dfs(start_pos, INF))
            ret += di;
    }
    return ret;
}

void build()
{
    queue<int> q;
    for (int i = 0; i < 2; i++)
        if (ch[1][i])
            fail[ch[1][i]] = 1, q.push(ch[1][i]);
        else
            ch[1][i] = 1;
    while (!q.empty())
    {
        int u = q.front();
        q.pop();
        for (int c = 0; c < 2; c++)
            if (ch[u][c])
                fail[ch[u][c]] = ch[fail[u]][c], q.push(ch[u][c]);
            else
                ch[u][c] = ch[fail[u]][c];
    }
    // simplify the paths;
    vector<int> path;
    for (int i = 1; i <= n; i++)
        for (int org = pos[i]; org != 1; org = fa[org])
        {
            int u = fail[org];
            path.clear();
            while (!tag[u])
                path.push_back(u), u = fail[u];
            while (!path.empty())
                fail[path.back()] = u, path.pop_back();
            fail[org] = u;
            if (org != pos[i] && tag[org])
                u = org;
            if (u != 1)
                mp[i][tag[u]] = true;
        }
}

int main()
{
    memset(head, -1, sizeof(head));
    scanf("%d", &n), tag[1] = -1;
    for (int ptr = 1, len; ptr <= n; ptr++)
    {
        scanf("%s", str + 1), len = strlen(str + 1);
        int p = 1;
        for (int i = 1; i <= len; i++)
        {
            if (ch[p][str[i] - 'a'] == 0)
                fa[ch[p][str[i] - 'a'] = ++ptot] = p;
            p = ch[p][str[i] - 'a'];
        }
        tag[p] = ptr, pos[ptr] = p;
    }
    build();
    for (int k = 1; k <= n; k++)
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                mp[i][j] |= mp[i][k] && mp[k][j];
    for (int i = 1; i <= n; i++)
        mp[i][i] = false;
    start_pos = 2 * n + 1, end_pos = start_pos + 1;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            if (mp[i][j])
                addtube(i, j + n, 1);
    for (int i = 1; i <= n; i++)
        addtube(start_pos, i, 1), addtube(i + n, end_pos, 1);
    printf("%d\n", n - dinic());
    for (int i = 1; i <= n; i++)
        if (dep[i] != 0 && dep[i + n] == 0)
            printf("%d ", i);
    puts("");
    return 0;
}


// CF590E.cpp
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1550, INF = 0x3f3f3f3f, MAX_S = 1e7 + 200;

int n, start_pos, end_pos, head[MAX_N], current, dep[MAX_N], cur[MAX_N], ptot = 1;
int ch[MAX_S][2], fail[MAX_S], tag[MAX_S], pos[MAX_N], fa[MAX_S];
bool mp[755][755];
char str[MAX_S];

struct edge
{
    int to, nxt, weight;
} edges[MAX_N * MAX_N];

void addpath(int src, int dst, int weight)
{
    edges[current].to = dst, edges[current].nxt = head[src];
    edges[current].weight = weight, head[src] = current++;
}

void addtube(int src, int dst, int weight)
{
    addpath(src, dst, weight);
    addpath(dst, src, 0);
}

bool bfs()
{
    memset(dep, 0, sizeof(dep));
    queue<int> q;
    q.push(start_pos), dep[start_pos] = 1;
    while (!q.empty())
    {
        int u = q.front();
        q.pop();
        for (int i = head[u]; i != -1; i = edges[i].nxt)
            if (edges[i].weight > 0 && dep[edges[i].to] == 0)
                dep[edges[i].to] = dep[u] + 1, q.push(edges[i].to);
    }
    return dep[end_pos] != 0;
}

int dfs(int u, int flow)
{
    if (u == end_pos || flow == 0)
        return flow;
    for (int &i = cur[u]; i != -1; i = edges[i].nxt)
        if (edges[i].weight > 0 && dep[edges[i].to] == dep[u] + 1)
            if (int di = dfs(edges[i].to, min(flow, edges[i].weight)))
            {
                edges[i].weight -= di, edges[i ^ 1].weight += di;
                return di;
            }
    return 0;
}

int dinic()
{
    int ret = 0;
    while (bfs())
    {
        memcpy(cur, head, sizeof(cur));
        while (int di = dfs(start_pos, INF))
            ret += di;
    }
    return ret;
}

void build()
{
    queue<int> q;
    for (int i = 0; i < 2; i++)
        if (ch[1][i])
            fail[ch[1][i]] = 1, q.push(ch[1][i]);
        else
            ch[1][i] = 1;
    while (!q.empty())
    {
        int u = q.front();
        q.pop();
        for (int c = 0; c < 2; c++)
            if (ch[u][c])
                fail[ch[u][c]] = ch[fail[u]][c], q.push(ch[u][c]);
            else
                ch[u][c] = ch[fail[u]][c];
    }
    // simplify the paths;
    vector<int> path;
    for (int i = 1; i <= n; i++)
        for (int org = pos[i]; org != 1; org = fa[org])
        {
            int u = fail[org];
            path.clear();
            while (!tag[u])
                path.push_back(u), u = fail[u];
            while (!path.empty())
                fail[path.back()] = u, path.pop_back();
            fail[org] = u;
            if (org != pos[i] && tag[org])
                u = org;
            if (u != 1)
                mp[i][tag[u]] = true;
        }
}

int main()
{
    memset(head, -1, sizeof(head));
    scanf("%d", &n), tag[1] = -1;
    for (int ptr = 1, len; ptr <= n; ptr++)
    {
        scanf("%s", str + 1), len = strlen(str + 1);
        int p = 1;
        for (int i = 1; i <= len; i++)
        {
            if (ch[p][str[i] - 'a'] == 0)
                fa[ch[p][str[i] - 'a'] = ++ptot] = p;
            p = ch[p][str[i] - 'a'];
        }
        tag[p] = ptr, pos[ptr] = p;
    }
    build();
    for (int k = 1; k <= n; k++)
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                mp[i][j] |= mp[i][k] && mp[k][j];
    for (int i = 1; i <= n; i++)
        mp[i][i] = false;
    start_pos = 2 * n + 1, end_pos = start_pos + 1;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            if (mp[i][j])
                addtube(i, j + n, 1);
    for (int i = 1; i <= n; i++)
        addtube(start_pos, i, 1), addtube(i + n, end_pos, 1);
    printf("%d\n", n - dinic());
    for (int i = 1; i <= n; i++)
        if (dep[i] != 0 && dep[i + n] == 0)
            printf("%d ", i);
    puts("");
    return 0;
}


#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 26, maxM = 10000003;

vector <pair <int, int> > E;
bool ban[maxN];

struct Aho
{
	int n, F[maxM], N[maxM], o[maxM];
	map <int, int> T[maxM];
	int Q[maxM];

	void add(string& t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int u = T[v][t[i] - 'a'];
			if (u == 0)
				T[v][t[i] - 'a'] = u = ++n;
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		int qf = 0, qb = 0;
		FOR(c, 0, Alph)
		{
			int u = T[1][c];
			if (u == 0)	T[1][c] = u = 1;
			else 		F[u] = 1, Q[qb++] = u;
		}
		while (qf != qb)
		{
			int v = Q[qf++];
			FOR(c, 0, Alph)
			{
				int u = T[v][c], w = F[v];
				if (u == 0)
					continue;
				F[u] = T[w][c];
				N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q[qb++] = u;
			}
		}
	}
	void query(string& t, int m, int x)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int c = t[i] - 'a';
			while (T[v].count(c) == 0)
				v = F[v];
			v = T[v][c];
			int u = o[v] == 0 ? N[v] : v;
			for (; u != 0; u = N[u])	E.pb({o[u]-1, x});
		}
	}
	void clean(int v = 1)
	{
		FOR(c, 0, Alph)
		{
			if (T[v][c] > 1)	clean(T[v][c]);
			T[v][c] = 0;
		}
		F[v] = N[v] = o[v] = 0;	n = 1;
	}
}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

vector <int> G[maxN];
string T[maxN];
int partner[maxN];
bool g[maxN][maxN];

void solve()
{
	int n;
	cin >> n;
	aho.clean();
	FOR(i, 0, n)
	{
		cin >> T[i];
		aho.add(T[i], SZ(T[i]), i);
	}
	aho.calcF();
	FOR(i, 0, n)
		if (!ban[i])
			aho.query(T[i], SZ(T[i]), i);

	for (auto [a, b] : E)
		if (a != b)
			g[a][b] = true;

	FOR(k, 0, n) FOR(i, 0, n) FOR(j, 0, n)
		if (g[i][k] and g[k][j])
			g[i][j] = true;

	FOR(i, 1, n+1) FOR(j, 1, n+1)
		if (g[i-1][j-1])
			G[n+i].pb(j), G[j].pb(n+i);

	mtg.run(G, n, n, partner);

	vector <int> ans;
	FOR(i, 0, n)
		if (!ban[i] and partner[i+1] == 0)
			ans.pb(i+1);

	cout << SZ(ans) << "\n";
	for (int v : ans)
		cout <<  v << " ";
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 26, maxM = 10000003;

vector <pair <int, int> > E;
bool ban[maxN];

struct Aho
{
	int n, F[maxM], o[maxM], N[maxN];
	vector <pair <char, int> > T[maxM];
	int Q[maxM];

	int getSon(int v, char c)
	{
		for (auto [d, u] : T[v])
			if (d == c)
				return u;
		return 0;
	}

	void add(string& t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int u = getSon(v, t[i]);
			if (u == 0)
				T[v].pb({t[i], ++n}), u = n;
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		int qf = 0, qb = 0;
		FOR(c, 0, Alph)
		{
			int u = getSon(1, 'a'+c);
			if (u == 0)	T[1].pb({'a'+c, 1});
			else 		F[u] = 1, Q[qb++] = u;
		}
		while (qf != qb)
		{
			int v = Q[qf++];
			FOR(c, 0, Alph)
			{
				int u = getSon(v, 'a'+c);
				if (u == 0)
					continue;
				F[u] = F[v];
				while (getSon(F[u], 'a'+c) == 0)
					F[u] = F[F[u]];
				F[u] = getSon(F[u], 'a'+c);
				N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q[qb++] = u;
			}
		}
	}
	void query(string& t, int m, int x)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			while (getSon(v, t[i]) == 0)
				v = F[v];
			v = getSon(v, t[i]);
			for (int u = v; u > 1; u = N[u])
				if (o[u] != 0)
					E.pb({o[u]-1, x});
		}
	}

}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

vector <int> G[maxN];
string T[maxN];
int partner[maxN];
bool g[maxN][maxN];

void solve()
{
	int n;
	cin >> n;
	aho.n = 1;
	FOR(i, 0, n)
	{
		cin >> T[i];
		aho.add(T[i], SZ(T[i]), i);
	}
	aho.calcF();
	FOR(i, 0, n)
		if (!ban[i])
			aho.query(T[i], SZ(T[i]), i);

	for (auto [a, b] : E)
		if (a != b)
			g[a][b] = true;

	FOR(k, 0, n) FOR(i, 0, n) FOR(j, 0, n)
		if (g[i][k] and g[k][j])
			g[i][j] = true;

	FOR(i, 1, n+1) FOR(j, 1, n+1)
		if (g[i-1][j-1])
			G[n+i].pb(j), G[j].pb(n+i);

	mtg.run(G, n, n, partner);

	vector <int> ans;
	FOR(i, 0, n)
		if (!ban[i] and partner[i+1] == 0)
			ans.pb(i+1);

	cout << SZ(ans) << "\n";
	for (int v : ans)
		cout <<  v << " ";
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 26;

vector <pair <int, int> > E;
bool ban[maxN];

struct Aho
{	/*usage: clean(),add(),calcF(),query(). query() zwraca pary postaci
	<KONIEC wystapienia, ind. klucza>. Teksty i klucze ind. od zera*/
	int n, T[maxN][Alph], F[maxN], N[maxN], o[maxN];
	queue <int> Q;
	void add(string& t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int& u = T[v][t[i] - 'a'];
			if (u == 0)	u = ++n;
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		FOR(c, 0, Alph)
		{
			int& u = T[1][c];
			if (u == 0)	u = 1;
			else 		F[u] = 1, Q.push(u);
		}
		while (!Q.empty())
		{
			int v = Q.front();	Q.pop();
			FOR(c, 0, Alph)
			{
				int &u = T[v][c], w = F[v];
				if (u == 0)
				{
					u = T[w][c];
					continue;
				}
				F[u] = T[w][c];
				N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q.push(u);
			}
		}
	}
	void query(string& t, int m, int x)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			v = T[v][t[i] - 'a'];
			int u = o[v] == 0 ? N[v] : v;
			for (; u != 0; u = N[u])	E.pb({o[u]-1, x});
		}
	}
	void clean(int v = 1)
	{
		FOR(c, 0, Alph)
		{
			if (T[v][c] > 1)	clean(T[v][c]);
			T[v][c] = 0;
		}
		F[v] = N[v] = o[v] = 0;	n = 1;
	}
}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

vector <int> G[maxN];
string T[maxN];
int partner[maxN];

void solve()
{
	int n;
	cin >> n;
	aho.clean();
	FOR(i, 0, n)
	{
		cin >> T[i];
		aho.add(T[i], SZ(T[i]), i);
	}
	aho.calcF();
	FOR(i, 0, n)
		if (!ban[i])
			aho.query(T[i], SZ(T[i]), i);

	for (auto [a, b] : E)
	{
		a++, b++;
		if (a != b)
			G[n+a].pb(b), G[b].pb(n+a);
	}

	mtg.run(G, n, n, partner);

	vector <int> ans;
	FOR(i, 0, n)
		if (!ban[i] and partner[i+1] == 0)
			ans.pb(i+1);

	cout << SZ(ans) << "\n";
	for (int v : ans)
		cout <<  v << " ";
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 2, maxM = 10000004;

int W;
bool ban[maxN], g[800][800];
vector <int> G[maxN];

struct Aho
{
	int n, T[maxM][Alph], F[maxM], N[maxM], o[maxM], Q[maxM];
	void add(string& t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int& u = T[v][t[i] - 'a'];
			if (u == 0)	u = ++n;
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		int qf = 0, qb = 0;
		FOR(c, 0, Alph)
		{
			int& u = T[1][c];
			if (u == 0)	u = 1;
			else 		F[u] = 1, Q[qb++] = u;
		}
		while (qf != qb)
		{
			int v = Q[qf++];
			FOR(c, 0, Alph)
			{
				int &u = T[v][c], w = F[v];
				if (u == 0)
				{
					u = T[w][c];
					continue;
				}
				F[u] = T[w][c];
				N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q[qb++] = u;
			}
		}
	}
	void query(string& t, int m, int x)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			v = T[v][t[i] - 'a'];
			int u = o[v] == 0 ? N[v] : v;
			for (; u != 0; u = N[u])
			{
				int y = o[u];
				if (x == y or g[y][x])
					continue;
				G[y+W].pb(x);
				G[x].pb(y+W);
				g[y][x] = true;
			}
		}
	}
}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

struct VerCover
{
    vector <int>* G;
    int* part;
    bool* res;
    void dfs(int v)
    {
        for (int u : G[v])
            if (part[u] != 0 and !res[u])
            {	res[u] = true;	dfs(part[u]);	}
    }

    void run(vector <int>* g, int n, int* Pin, bool* Rout)
    {
        G = g, part = Pin, res = Rout;
        FOR(i, 1, n+1)	if (part[i] == 0)	dfs(i);
        FOR(i, 1, n+1)
            if (part[i] != 0 and !res[part[i]])
                res[i] = true;
    }
}cover;

string T[maxN];
int partner[maxN];
bool vc[maxN];

void solve()
{
	cin >> W;
	aho.n = 1;
	FOR(i, 0, W)
	{
		cin >> T[i];
		aho.add(T[i], SZ(T[i]), i);
	}
	aho.calcF();
	FOR(i, 0, W)
		if (!ban[i])
			aho.query(T[i], SZ(T[i]), i+1);

	mtg.run(G, W, W, partner);
	cover.run(G, W, partner, vc);

	dbg(G, W*2+1);
	dbg(vc, W*2+1);

	vector <int> ans;
	FOR(i, 0, W)
		if (!ban[i] and !vc[i+1])
			ans.pb(i+1);
/*
	while (true)
	{
		int s = SZ(ans);
		bool ok = true;
		FOR(i, 0, s) FOR(j, 0, s)
			while (g[ans[i]][ans[j]])
				ans[i] = partner[W+ans[i]], ok = false;
		if (ok)
			break;
	}
*/
	cout << SZ(ans) << "\n";
	for (int v : ans)
		cout <<  v << " ";
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 26, maxM = 10000003;

vector <pair <int, int> > E;
bool ban[maxN];

struct Aho
{
	int n, F[maxM], o[maxM], N[maxM];
	vector <pair <char, int> > T[maxM];
	int Q[maxM];

	int getSon(int v, char c)
	{
		for (auto [d, u] : T[v])
			if (d == c)
				return u;
		return 0;
	}

	void add(string& t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int u = getSon(v, t[i]);
			if (u == 0)
				T[v].pb({t[i], ++n}), u = n;
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		int qf = 0, qb = 0;
		FOR(c, 0, Alph)
		{
			int u = getSon(1, 'a'+c);
			if (u == 0)	T[1].pb({'a'+c, 1});
			else 		F[u] = 1, Q[qb++] = u;
		}
		while (qf != qb)
		{
			int v = Q[qf++];
			FOR(c, 0, Alph)
			{
				int u = getSon(v, 'a'+c);
				if (u == 0)
					continue;
				F[u] = F[v];
				while (getSon(F[u], 'a'+c) == 0)
					F[u] = F[F[u]];
				F[u] = getSon(F[u], 'a'+c);
				N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q[qb++] = u;
			}
		}
	}
	void query(string& t, int m, int x)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			while (getSon(v, t[i]) == 0)
				v = F[v];
			v = getSon(v, t[i]);
			for (int u = v; u > 1; u = N[u])
				if (o[u] != 0)
					E.pb({o[u]-1, x});
		}
	}

}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

vector <int> G[maxN];
string T[maxN];
int partner[maxN];
bool g[maxN][maxN];

void solve()
{
	int n;
	cin >> n;
	aho.n = 1;
	FOR(i, 0, n)
	{
		cin >> T[i];
		aho.add(T[i], SZ(T[i]), i);
	}
	aho.calcF();
	FOR(i, 0, n)
		if (!ban[i])
			aho.query(T[i], SZ(T[i]), i);

	for (auto [a, b] : E)
		if (a != b)
			g[a][b] = true;

	FOR(k, 0, n) FOR(i, 0, n) FOR(j, 0, n)
		if (g[i][k] and g[k][j])
			g[i][j] = true;

	FOR(i, 1, n+1) FOR(j, 1, n+1)
		if (g[i-1][j-1])
			G[n+i].pb(j), G[j].pb(n+i);

	mtg.run(G, n, n, partner);

	vector <int> ans;
	FOR(i, 0, n)
		if (!ban[i] and partner[i+1] == 0)
			ans.pb(i+1);

	cout << SZ(ans) << "\n";
	for (int v : ans)
		cout <<  v << " ";
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 2, maxM = 10008004;

int W;
bool ban[maxN], g[800][800];
vector <int> G[maxN];

struct Aho
{
	int n, T[maxM][Alph], F[maxM], N[maxM], o[maxM], Q[maxM];
	void add(char* t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int& u = T[v][t[i] - 'a'];
			if (u == 0)	u = ++n;
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		int qf = 0, qb = 0;
		FOR(c, 0, Alph)
		{
			int& u = T[1][c];
			if (u == 0)	u = 1;
			else 		F[u] = 1, Q[qb++] = u;
		}
		while (qf != qb)
		{
			int v = Q[qf++];
			FOR(c, 0, Alph)
			{
				int &u = T[v][c], w = F[v];
				if (u == 0)
				{
					u = T[w][c];
					continue;
				}
				F[u] = T[w][c];
				N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q[qb++] = u;
			}
		}
	}
	void query(char* t, int m, int x)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			v = T[v][t[i] - 'a'];
			int u = o[v] == 0 ? N[v] : v;
			for (; u != 0; u = N[u])
			{
				int y = o[u];
				if (x == y)
					continue;
				G[y+W].pb(x);
				G[x].pb(y+W);
				g[y][x] = true;
			}
		}
	}
}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

char mem[maxM], *in = mem;
int partner[maxN];
vector <char*> T;
int len[maxN];

void solve()
{
	cin >> W;
	aho.n = 1;
	FOR(i, 0, W)
	{
		scanf ("%s", in);
		T.pb(in);
		len[i] = strlen(in);
		in += len[i]+1;
		aho.add(T[i], len[i], i);
	}
	aho.calcF();
	FOR(i, 0, W)
		if (!ban[i])
			aho.query(T[i], len[i], i+1);

	mtg.run(G, W, W, partner);

	vector <int> ans;
	FOR(i, 0, W)
		if (!ban[i] and partner[i+1] == 0)
			ans.pb(i+1);

	dbg(ans);
	dbg(W);
	dbg(G, W+1);

	while (true)
	{
		int s = SZ(ans);
		bool ok = true;
		FOR(i, 0, s) FOR(j, 0, s)
			if (g[ans[i]][ans[j]])
				ans[i] = partner[W+ans[i]], ok = false;
		if (ok)
			break;
	}

	printf("%d\n", SZ(ans));//cout << SZ(ans) << "\n";
	for (int v : ans)
		printf("%d ", v);//cout <<  v << " ";
	printf( "\n");
}

int main()
{
	//ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 2, maxM = 10000004;

int W;
bool ban[maxN], g[800][800];
vector <int> G[maxN];

struct Aho
{
	int n, T[maxM][Alph], F[maxM], N[maxM], o[maxM], Q[maxM];
	void add(string& t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int& u = T[v][t[i] - 'a'];
			if (u == 0)	u = ++n;
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		int qf = 0, qb = 0;
		FOR(c, 0, Alph)
		{
			int& u = T[1][c];
			if (u == 0)	u = 1;
			else 		F[u] = 1, Q[qb++] = u;
		}
		while (qf != qb)
		{
			int v = Q[qf++];
			FOR(c, 0, Alph)
			{
				int &u = T[v][c], w = F[v];
				if (u == 0)
				{
					u = T[w][c];
					continue;
				}
				F[u] = T[w][c];
				N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q[qb++] = u;
			}
		}
	}
	void query(string& t, int m, int x)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			v = T[v][t[i] - 'a'];
			int u = o[v] == 0 ? N[v] : v;
			for (; u != 0; u = N[u])
			{
				int y = o[u];
				if (x == y or g[y][x])
					continue;
				G[y+W].pb(x);
				G[x].pb(y+W);
				g[y][x] = true;
			}
		}
	}
}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

string T[maxN];
int partner[maxN];

void solve()
{
	cin >> W;
	aho.n = 1;
	FOR(i, 0, W)
	{
		cin >> T[i];
		aho.add(T[i], SZ(T[i]), i);
	}
	aho.calcF();
	FOR(i, 0, W)
		if (!ban[i])
			aho.query(T[i], SZ(T[i]), i+1);

	mtg.run(G, W, W, partner);

	vector <int> ans;
	FOR(i, 0, W)
		if (!ban[i] and partner[i+1] == 0)
			ans.pb(i+1);

	while (true)
	{
		int s = SZ(ans);
		bool ok = true;
		FOR(i, 0, s) FOR(j, 0, s)
			while (g[ans[i]][ans[j]])
				ans[i] = partner[W+ans[i]], ok = false;
		if (ok)
			break;
	}

	cout << SZ(ans) << "\n";
	for (int v : ans)
		cout <<  v << " ";
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 2, maxM = 10000004;

vector <pair <int, int> > E;
bool ban[maxN];

struct Aho
{
	int n, T[maxM][Alph], F[maxM], N[maxM], o[maxM];
	queue <int> Q;
	void add(string& t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int& u = T[v][t[i] - 'a'];
			if (u == 0)	u = ++n;
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		FOR(c, 0, Alph)
		{
			int& u = T[1][c];
			if (u == 0)	u = 1;
			else 		F[u] = 1, Q.push(u);
		}
		while (!Q.empty())
		{
			int v = Q.front();	Q.pop();
			FOR(c, 0, Alph)
			{
				int &u = T[v][c], w = F[v];
				if (u == 0)
				{
					u = T[w][c];
					continue;
				}
				F[u] = T[w][c];
				N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q.push(u);
			}
		}
	}
	void query(string& t, int m, int x)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			v = T[v][t[i] - 'a'];
			int u = o[v] == 0 ? N[v] : v;
			for (; u != 0; u = N[u])	E.pb({o[u]-1, x});
		}
	}
}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

vector <int> G[maxN];
string T[maxN];
int partner[maxN];
bool g[maxN][maxN];

void solve()
{
	int n;
	cin >> n;
	aho.n = 1;
	FOR(i, 0, n)
	{
		cin >> T[i];
		aho.add(T[i], SZ(T[i]), i);
	}
	aho.calcF();
	FOR(i, 0, n)
		if (!ban[i])
			aho.query(T[i], SZ(T[i]), i);

	for (auto [a, b] : E)
	{
		a++, b++;
		if (a != b)
			G[n+a].pb(b), G[b].pb(n+a), g[a][b] = true;

	}

	mtg.run(G, n, n, partner);

	vector <int> ans;
	FOR(i, 0, n)
		if (!ban[i] and partner[i+1] == 0)
			ans.pb(i+1);

	while (true)
	{
		int s = SZ(ans);
		bool ok = true;
		FOR(i, 0, s) FOR(j, 0, s)
			if (g[ans[i]][ans[j]])
				ans[i] = partner[n+ans[i]], ok = false;
		if (ok)
			break;
	}

	cout << SZ(ans) << "\n";
	for (int v : ans)
		cout <<  v << " ";
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 2, maxM = 10000004;

int W;
bool ban[maxN], g[800][800];

struct Aho
{
	int n, T[maxM][Alph], F[maxM], N[maxM], o[maxM], Q[maxM], vis[maxM], visCtr;
	void add(string& t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int& u = T[v][t[i] - 'a'];
			if (u == 0)	u = ++n;
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		int qf = 0, qb = 0;
		FOR(c, 0, Alph)
		{
			int& u = T[1][c];
			if (u == 0)	u = 1;
			else 		F[u] = 1, Q[qb++] = u;
		}
		while (qf != qb)
		{
			int v = Q[qf++];
			FOR(c, 0, Alph)
			{
				int &u = T[v][c], w = F[v];
				if (u == 0)
				{
					u = T[w][c];
					continue;
				}
				F[u] = T[w][c];
				N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q[qb++] = u;
			}
		}
	}
	void query(string& t, int m, int x)
	{
		vis[0] = vis[1] = ++visCtr;
		int v = 1;
		FOR(i, 0, m)
		{
			v = T[v][t[i] - 'a'];
			int u = o[v] == 0 ? N[v] : v;
			for (; vis[u]!=visCtr; u=N[u])
			{
				int y = o[u];
				if (x != y and y != 0)
					g[y][x] = true;
				vis[u] = visCtr;
			}
		}
	}
}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

struct VerCover
{
    vector <int>* G;
    int* part;
    bool* res;
    void dfs(int v)
    {
        for (int u : G[v])
            if (part[u] != 0 and !res[u])
            {	res[u] = true;	dfs(part[u]);	}
    }

    void run(vector <int>* g, int n, int* Pin, bool* Rout)
    {
        G = g, part = Pin, res = Rout;
        FOR(i, 1, n+1)	if (part[i] == 0)	dfs(i);
        FOR(i, 1, n+1)
            if (part[i] != 0 and !res[part[i]])
                res[i] = true;
    }
}cover;

string T[maxN];
int partner[maxN];
bool vc[maxN];
vector <int> G[maxN];

void solve()
{
	cin >> W;
	aho.n = 1;
	FOR(i, 0, W)
	{
		cin >> T[i];
		aho.add(T[i], SZ(T[i]), i);
	}
	aho.calcF();
	FOR(i, 0, W)
		if (!ban[i])
			aho.query(T[i], SZ(T[i]), i+1);

	FOR(k, 1, W+1) FOR(i, 1, W+1) FOR(j, 1, W+1)
		if (g[i][k] and g[k][j])
			g[i][j] = true;
	FOR(i, 1, W+1) FOR(j, 1, W+1)
		if (g[i][j])
			G[i+W].pb(j), G[j].pb(i+W);

	mtg.run(G, W, W, partner);
	cover.run(G, W, partner, vc);

	dbg(G, W*2+1);
	dbg(vc, W*2+1);

	vector <int> ans;
	FOR(i, 0, W)
		if (!ban[i] and !vc[i+1] and !vc[i+1+W])
			ans.pb(i+1);
/*
	while (true)
	{
		int s = SZ(ans);
		bool ok = true;
		FOR(i, 0, s) FOR(j, 0, s)
			while (g[ans[i]][ans[j]])
				ans[i] = partner[W+ans[i]], ok = false;
		if (ok)
			break;
	}
*/
	cout << SZ(ans) << "\n";
	for (int v : ans)
		cout <<  v << " ";
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 26, maxM = 10000003;

vector <pair <int, int> > E;
bool ban[maxN];

struct Aho
{
	int n, F[maxM], o[maxM];
	vector <pair <char, int> > T[maxM];
	int Q[maxM];

	int getSon(int v, char c)
	{
		for (auto [d, u] : T[v])
			if (d == c)
				return u;
		return 0;
	}

	void add(string& t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int u = getSon(v, t[i]);
			if (u == 0)
				T[v].pb({t[i], ++n}), u = n;
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		int qf = 0, qb = 0;
		FOR(c, 0, Alph)
		{
			int u = getSon(1, 'a'+c);
			if (u == 0)	T[1].pb({'a'+c, 1});
			else 		F[u] = 1, Q[qb++] = u;
		}
		while (qf != qb)
		{
			int v = Q[qf++];
			FOR(c, 0, Alph)
			{
				int u = getSon(v, 'a'+c);
				if (u == 0)
					continue;
				F[u] = F[v];
				while (getSon(F[u], 'a'+c) == 0)
					F[u] = F[F[u]];
				F[u] = getSon(F[u], 'a'+c);
				//N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q[qb++] = u;
			}
		}
	}
	void query(string& t, int m, int x)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			while (getSon(v, t[i]) == 0)
				v = F[v];
			v = getSon(v, t[i]);
			for (int u = v; u != 1; u = F[u])
				if (o[u] != 0)
					E.pb({o[u]-1, x});
		}
	}

}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

vector <int> G[maxN];
string T[maxN];
int partner[maxN];
bool g[maxN][maxN];

void solve()
{
	int n;
	cin >> n;
	aho.n = 1;
	FOR(i, 0, n)
	{
		cin >> T[i];
		aho.add(T[i], SZ(T[i]), i);
	}
	aho.calcF();
	FOR(i, 0, n)
		if (!ban[i])
			aho.query(T[i], SZ(T[i]), i);

	for (auto [a, b] : E)
		if (a != b)
			g[a][b] = true;

	FOR(k, 0, n) FOR(i, 0, n) FOR(j, 0, n)
		if (g[i][k] and g[k][j])
			g[i][j] = true;

	FOR(i, 1, n+1) FOR(j, 1, n+1)
		if (g[i-1][j-1])
			G[n+i].pb(j), G[j].pb(n+i);

	mtg.run(G, n, n, partner);

	vector <int> ans;
	FOR(i, 0, n)
		if (!ban[i] and partner[i+1] == 0)
			ans.pb(i+1);

	cout << SZ(ans) << "\n";
	for (int v : ans)
		cout <<  v << " ";
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 2, maxM = 10000004;

int W;
bool ban[maxN], g[800][800];

struct Aho
{
	int n, T[maxM][Alph], F[maxM], N[maxM], o[maxM], Q[maxM], vis[maxN], visCtr;
	void add(string& t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int& u = T[v][t[i] - 'a'];
			if (u == 0)	u = ++n;
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		int qf = 0, qb = 0;
		FOR(c, 0, Alph)
		{
			int& u = T[1][c];
			if (u == 0)	u = 1;
			else 		F[u] = 1, Q[qb++] = u;
		}
		while (qf != qb)
		{
			int v = Q[qf++];
			FOR(c, 0, Alph)
			{
				int &u = T[v][c], w = F[v];
				if (u == 0)
				{
					u = T[w][c];
					continue;
				}
				F[u] = T[w][c];
				N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q[qb++] = u;
			}
		}
	}
	void query(string& t, int m, int x)
	{
		vis[0] = vis[1] = ++visCtr;
		int v = 1;
		FOR(i, 0, m)
		{
			v = T[v][t[i] - 'a'];
			int u = o[v] == 0 ? N[v] : v;
			for (; !vis[u]; u=N[u])
			{
				int y = o[u];
				if (x != y and y != 0)
					g[y][x] = true;
			}
		}
	}
}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

struct VerCover
{
    vector <int>* G;
    int* part;
    bool* res;
    void dfs(int v)
    {
        for (int u : G[v])
            if (part[u] != 0 and !res[u])
            {	res[u] = true;	dfs(part[u]);	}
    }

    void run(vector <int>* g, int n, int* Pin, bool* Rout)
    {
        G = g, part = Pin, res = Rout;
        FOR(i, 1, n+1)	if (part[i] == 0)	dfs(i);
        FOR(i, 1, n+1)
            if (part[i] != 0 and !res[part[i]])
                res[i] = true;
    }
}cover;

string T[maxN];
int partner[maxN];
bool vc[maxN];
vector <int> G[maxN];

void solve()
{
	cin >> W;
	aho.n = 1;
	FOR(i, 0, W)
	{
		cin >> T[i];
		aho.add(T[i], SZ(T[i]), i);
	}
	aho.calcF();
	FOR(i, 0, W)
		if (!ban[i])
			aho.query(T[i], SZ(T[i]), i+1);

	FOR(k, 1, W+1) FOR(i, 1, W+1) FOR(j, 1, W+1)
		if (g[i][k] and g[k][j])
			g[i][j] = true;
	FOR(i, 1, W+1) FOR(j, 1, W+1)
		if (g[i][j])
			G[i+W].pb(j), G[j].pb(i+W);

	mtg.run(G, W, W, partner);
	cover.run(G, W, partner, vc);

	dbg(G, W*2+1);
	dbg(vc, W*2+1);

	vector <int> ans;
	FOR(i, 0, W)
		if (!ban[i] and !vc[i+1] and !vc[i+1+W])
			ans.pb(i+1);
/*
	while (true)
	{
		int s = SZ(ans);
		bool ok = true;
		FOR(i, 0, s) FOR(j, 0, s)
			while (g[ans[i]][ans[j]])
				ans[i] = partner[W+ans[i]], ok = false;
		if (ok)
			break;
	}
*/
	cout << SZ(ans) << "\n";
	for (int v : ans)
		cout <<  v << " ";
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 26, maxM = 10000003;

vector <pair <int, int> > E;
bool ban[maxN];

struct Aho
{
	int n, F[maxM], o[maxM], N[maxM];
	vector <pair <char, int> > T[maxM];
	int Q[maxM];

	int getSon(int v, char c)
	{
		for (auto [d, u] : T[v])
			if (d == c)
				return u;
		return 0;
	}

	void add(string& t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int u = getSon(v, t[i]);
			if (u == 0)
			{
				T[v].pb({t[i], ++n});
				u = n;
			}
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		int qf = 0, qb = 0;
		FOR(c, 'a', 'z'+1)
		{
			int u = getSon(1, c);
			if (u == 0)	T[1].pb({c, 1});
			else 		F[u] = 1, Q[qb++] = u;
		}
		while (qf != qb)
		{
			int v = Q[qf++];
			FOR(c, 'a', 'z'+1)
			{
				int u = getSon(v, c);
				if (u == 0)
					continue;
				F[u] = F[v];
				while (getSon(F[u], c) == 0)
					F[u] = F[F[u]];
				F[u] = getSon(F[u], c);
				N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q[qb++] = u;
			}
		}
	}
	void query(string& t, int m, int x)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			while (getSon(v, t[i]) == 0)
				v = F[v];
			v = getSon(v, t[i]);
			for (int u = v; u > 1; u = N[u])
				if (o[u] != 0)
					E.pb({o[u]-1, x});
		}
	}

}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

vector <int> G[maxN];
string T[maxN];
int partner[maxN];
bool g[maxN][maxN];

void solve()
{
	int n;
	cin >> n;
	aho.n = 1;
	FOR(i, 0, n)
	{
		cin >> T[i];
		aho.add(T[i], SZ(T[i]), i);
	}
	aho.calcF();
	FOR(i, 0, n)
		if (!ban[i])
			aho.query(T[i], SZ(T[i]), i);

	for (auto [a, b] : E)
		if (a != b)
			g[a][b] = true;

	FOR(k, 0, n) FOR(i, 0, n) FOR(j, 0, n)
		if (g[i][k] and g[k][j])
			g[i][j] = true;

	FOR(i, 1, n+1) FOR(j, 1, n+1)
		if (g[i-1][j-1])
			G[n+i].pb(j), G[j].pb(n+i);

	mtg.run(G, n, n, partner);

	vector <int> ans;
	FOR(i, 0, n)
		if (!ban[i] and partner[i+1] == 0)
			ans.pb(i+1);

	cout << SZ(ans) << "\n";
	for (int v : ans)
		cout <<  v << " ";
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 26, maxM = 10000003;

vector <pair <int, int> > E;
bool ban[maxN];

struct Aho
{
	int n, F[maxM], N[maxM], o[maxM];
	unordered_map <int, int> T[maxM];
	int Q[maxM];

	void add(string& t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int u = T[v][t[i] - 'a'];
			if (u == 0)
				T[v][t[i] - 'a'] = u = ++n;
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		int qf = 0, qb = 0;
		FOR(c, 0, Alph)
		{
			int u = T[1][c];
			if (u == 0)	T[1][c] = u = 1;
			else 		F[u] = 1, Q[qb++] = u;
		}
		while (qf != qb)
		{
			int v = Q[qf++];
			FOR(c, 0, Alph)
			{
				int u = T[v][c];
				if (u == 0)
					continue;
				F[u] = F[v];
				while (T[F[u]][c] == 0)
					F[u] = F[F[u]];
				F[u] = T[F[u]][c];
				N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q[qb++] = u;
			}
		}
	}
	void query(string& t, int m, int x)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int c = t[i] - 'a';
			while (T[v].count(c) == 0)
				v = F[v];
			v = T[v][c];
			for (int u = v; u != 1; u = F[u])
				if (o[u] != 0)
					E.pb({o[u]-1, x});
		}
	}
	void clean(int v = 1)
	{
		FOR(c, 0, Alph)
		{
			if (T[v][c] > 1)	clean(T[v][c]);
			T[v][c] = 0;
		}
		F[v] = N[v] = o[v] = 0;	n = 1;
	}
}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

vector <int> G[maxN];
string T[maxN];
int partner[maxN];
bool g[maxN][maxN];

void solve()
{
	int n;
	cin >> n;
	aho.clean();
	FOR(i, 0, n)
	{
		cin >> T[i];
		aho.add(T[i], SZ(T[i]), i);
	}
	aho.calcF();
	FOR(i, 0, n)
		if (!ban[i])
			aho.query(T[i], SZ(T[i]), i);

	for (auto [a, b] : E)
		if (a != b)
			g[a][b] = true;

	FOR(k, 0, n) FOR(i, 0, n) FOR(j, 0, n)
		if (g[i][k] and g[k][j])
			g[i][j] = true;

	FOR(i, 1, n+1) FOR(j, 1, n+1)
		if (g[i-1][j-1])
			G[n+i].pb(j), G[j].pb(n+i);

	mtg.run(G, n, n, partner);

	vector <int> ans;
	FOR(i, 0, n)
		if (!ban[i] and partner[i+1] == 0)
			ans.pb(i+1);

	cout << SZ(ans) << "\n";
	for (int v : ans)
		cout <<  v << " ";
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 2, maxM = 10000004;

vector <pair <int, int> > E;
bool ban[maxN];

struct Aho
{	int n, T[maxM][Alph], F[maxM], N[maxM], o[maxM];
	queue <int> Q;
	void add(string& t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int& u = T[v][t[i] - 'a'];
			if (u == 0)	u = ++n;
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		FOR(c, 0, Alph)
		{
			int& u = T[1][c];
			if (u == 0)	u = 1;
			else 		F[u] = 1, Q.push(u);
		}
		while (!Q.empty())
		{
			int v = Q.front();	Q.pop();
			FOR(c, 0, Alph)
			{
				int &u = T[v][c], w = F[v];
				if (u == 0)
				{
					u = T[w][c];
					continue;
				}
				F[u] = T[w][c];
				N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q.push(u);
			}
		}
	}
	void query(string& t, int m, int x)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			v = T[v][t[i] - 'a'];
			int u = o[v] == 0 ? N[v] : v;
			for (; u != 0; u = N[u])	E.pb({o[u]-1, x});
		}
	}
}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

vector <int> G[maxN];
string T[maxN];
int partner[maxN];

void solve()
{
	int n;
	cin >> n;
	aho.n = 1;
	FOR(i, 0, n)
	{
		cin >> T[i];
		aho.add(T[i], SZ(T[i]), i);
	}
	aho.calcF();
	FOR(i, 0, n)
		if (!ban[i])
			aho.query(T[i], SZ(T[i]), i);

	for (auto [a, b] : E)
	{
		a++, b++;
		if (a != b)
			G[n+a].pb(b), G[b].pb(n+a);
	}

	mtg.run(G, n, n, partner);

	vector <int> ans;
	FOR(i, 0, n)
		if (!ban[i] and partner[i+1] == 0)
			ans.pb(i+1);

	cout << SZ(ans) << "\n";
	for (int v : ans)
		cout <<  v << " ";
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 26, maxM = 10000003;

vector <pair <int, int> > E;
bool ban[maxN];

struct Aho
{
	int n, F[maxM], N[maxM], o[maxM];
	map <int, int> T[maxM];

	queue <int> Q;
	void add(string& t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int u = T[v][t[i] - 'a'];
			if (u == 0)
				T[v][t[i] - 'a'] = u = ++n;
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		FOR(c, 0, Alph)
		{
			int u = T[1][c];
			if (u == 0)	T[1][c] = u = 1;
			else 		F[u] = 1, Q.push(u);
		}
		while (!Q.empty())
		{
			int v = Q.front();	Q.pop();
			FOR(c, 0, Alph)
			{
				int u = T[v][c], w = F[v];
				if (u == 0)
				{
					T[v][c] = u = T[w][c];
					continue;
				}
				F[u] = T[w][c];
				N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q.push(u);
			}
		}
	}
	void query(string& t, int m, int x)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			v = T[v][t[i] - 'a'];
			int u = o[v] == 0 ? N[v] : v;
			for (; u != 0; u = N[u])	E.pb({o[u]-1, x});
		}
	}
	void clean(int v = 1)
	{
		FOR(c, 0, Alph)
		{
			if (T[v][c] > 1)	clean(T[v][c]);
			T[v][c] = 0;
		}
		F[v] = N[v] = o[v] = 0;	n = 1;
	}
}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

vector <int> G[maxN];
string T[maxN];
int partner[maxN];

void solve()
{
	int n;
	cin >> n;
	aho.clean();
	FOR(i, 0, n)
	{
		cin >> T[i];
		aho.add(T[i], SZ(T[i]), i);
	}
	aho.calcF();
	FOR(i, 0, n)
		if (!ban[i])
			aho.query(T[i], SZ(T[i]), i);

	for (auto [a, b] : E)
	{
		a++, b++;
		if (a != b)
			G[n+a].pb(b), G[b].pb(n+a);
	}

	mtg.run(G, n, n, partner);

	vector <int> ans;
	FOR(i, 0, n)
		if (!ban[i] and partner[i+1] == 0)
			ans.pb(i+1);

	cout << SZ(ans) << "\n";
	for (int v : ans)
		cout <<  v << " ";
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 26, maxM = 10000003;

vector <pair <int, int> > E;
bool ban[maxN];

struct Aho
{
	int n, F[maxM], N[maxM], o[maxM];
	map <int, int> T[maxM];
	int Q[maxM];

	void add(string& t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int u = T[v][t[i] - 'a'];
			if (u == 0)
				T[v][t[i] - 'a'] = u = ++n;
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		int qf = 0, qb = 0;
		FOR(c, 0, Alph)
		{
			int u = T[1][c];
			if (u == 0)	T[1][c] = u = 1;
			else 		F[u] = 1, Q[qb++] = u;
		}
		while (qf != qb)
		{
			int v = Q[qf++];
			FOR(c, 0, Alph)
			{
				int u = T[v][c], w = F[v];
				if (u == 0)
					continue;
				F[u] = T[w][c];
				N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q[qb++] = u;
			}
		}
	}
	void query(string& t, int m, int x)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int c = t[i] - 'a';
			while (T[v].count(c) == 0)
				v = F[v];
			v = T[v][c];
			int u = o[v] == 0 ? N[v] : v;
			for (; u != 0; u = N[u])	E.pb({o[u]-1, x});
		}
	}
	void clean(int v = 1)
	{
		FOR(c, 0, Alph)
		{
			if (T[v][c] > 1)	clean(T[v][c]);
			T[v][c] = 0;
		}
		F[v] = N[v] = o[v] = 0;	n = 1;
	}
}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

vector <int> G[maxN];
string T[maxN];
int partner[maxN];

void solve()
{
	int n;
	cin >> n;
	aho.clean();
	FOR(i, 0, n)
	{
		cin >> T[i];
		aho.add(T[i], SZ(T[i]), i);
	}
	aho.calcF();
	FOR(i, 0, n)
		if (!ban[i])
			aho.query(T[i], SZ(T[i]), i);

	for (auto [a, b] : E)
	{
		a++, b++;
		if (a != b)
			G[n+a].pb(b), G[b].pb(n+a);
	}

	mtg.run(G, n, n, partner);

	vector <int> ans;
	FOR(i, 0, n)
		if (!ban[i] and partner[i+1] == 0)
			ans.pb(i+1);

	cout << SZ(ans) << "\n";
	for (int v : ans)
		cout <<  v << " ";
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 2, maxM = 10000004;

vector <pair <int, int> > E;
bool ban[maxN];

struct Aho
{
	int n, T[maxM][Alph], F[maxM], N[maxM], o[maxM], Q[maxM];
	void add(string& t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int& u = T[v][t[i] - 'a'];
			if (u == 0)	u = ++n;
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		int qf = 0, qb = 0;
		FOR(c, 0, Alph)
		{
			int& u = T[1][c];
			if (u == 0)	u = 1;
			else 		F[u] = 1, Q[qb++] = u;
		}
		while (qf != qb)
		{
			int v = Q[qf++];
			FOR(c, 0, Alph)
			{
				int &u = T[v][c], w = F[v];
				if (u == 0)
				{
					u = T[w][c];
					continue;
				}
				F[u] = T[w][c];
				N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q[qb++] = u;
			}
		}
	}
	void query(string& t, int m, int x)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			v = T[v][t[i] - 'a'];
			int u = o[v] == 0 ? N[v] : v;
			for (; u != 0; u = N[u])	E.pb({o[u]-1, x});
		}
	}
}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

vector <int> G[maxN];
string T[maxN];
int partner[maxN];
bool g[800][800];

void solve()
{
	int n;
	cin >> n;
	aho.n = 1;
	FOR(i, 0, n)
	{
		cin >> T[i];
		aho.add(T[i], SZ(T[i]), i);
	}
	aho.calcF();
	FOR(i, 0, n)
		if (!ban[i])
			aho.query(T[i], SZ(T[i]), i);

	for (auto [a, b] : E)
	{
		a++, b++;
		if (a != b)
			G[n+a].pb(b), G[b].pb(n+a), g[a][b] = true;

	}

	mtg.run(G, n, n, partner);

	vector <int> ans;
	FOR(i, 0, n)
		if (!ban[i] and partner[i+1] == 0)
			ans.pb(i+1);

	while (true)
	{
		int s = SZ(ans);
		bool ok = true;
		FOR(i, 0, s) FOR(j, 0, s)
			if (g[ans[i]][ans[j]])
				ans[i] = partner[n+ans[i]], ok = false;
		if (ok)
			break;
	}

	cout << SZ(ans) << "\n";
	for (int v : ans)
		cout <<  v << " ";
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}