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


int br[20];

int Resi(int n, int k, int* l, char** a, char* s)
{
	for(int i=1;i<=n;i++)
	{
		br[i]=0;
		if(l[i]>18)return -1;
		for(int j=l[i];j>0;j--)
		{
			if(a[i][j]>'b')return -1;
			br[i]+=(1<<(l[i]-j))*(a[i][j]-'a');
		}
	}

	int minn=0;
	int minduz=19;
	for(int i=0;i<(1<<18);i++)
	{
		int minl=18;
		for(int j=1;j<=n;j++)
		{
			int tre=-1;

			int vre=i%(1<<l[j]);
			for(int p=l[j]-1;p<=17 && tre==-1;p++)
			{
				if(vre^br[j]==0)tre=p;

				vre/=2;
				if(br[i]&(1<<(p+1)))vre+=(1<<(l[j]-1));
			}

			minl=min(tre,minl);
		}

		if(minl!=-1 && minduz>minl+1)
		{
			minduz=minl+1;
			minn=i;
		}
	}

	if(minduz==19)return -1;

	for(int i=minduz-1;i>0;i--)
	{
		int x=minn & (1<<i);
		if(x==0)s[minduz-i]='a';
		else s[minduz-i]='b';
	}

	return minduz;
}