#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



enum Type{
	YES,
	NO,
	UNDEFINED,
};


int M;
int index_table;
int NUM[3][8005];
char INPUT[3][3005],table[3][8005];
Type type[26],ans_type[26];
bool is_OK,IS_UPPER[3][8005];


bool is_upper(char ch){

	return ch <= 'Z';
}

int get_num(char ch){

	if(is_upper(ch)){

		return ch-'A';
	}else{

		return ch-'a';
	}
}

bool check(int index){

	for(int row = 0; row < 3; row++){

		int tmp_ch = get_num(table[row][index]);

		if((IS_UPPER[row][index] == true && type[tmp_ch] == NO) ||
				(IS_UPPER[row][index] == false && type[tmp_ch] == YES)){

			return true;
		}
	}

	int ch[3];
	for(int row = 0; row < 3; row++){

		ch[row] = NUM[row][index];
	}

	//同種で大小が異なる文字がある
	for(int i = 0; i < 3; i++){
		if(ch[i] == ch[(i+1)%3] && table[i][index] != table[(i+1)%3][index]){
			return true;
		}
	}

	return false;
}

bool recursive(int index){

	if(is_OK)return true;

	if(index == index_table){

		for(int i = 0; i < 26; i++){

			ans_type[i] = type[i];
		}
		is_OK = true;
		return true;
	}

	//分岐不要
	if(check(index)){

		return recursive(index+1);
	}

	int undef[3];
	int undef_index = 0;
	for(int row = 0; row < 3; row++){
		if(type[NUM[row][index]] == UNDEFINED){

			undef[undef_index++] = row;
		}
	}

	if(undef_index == 0)return false;

	int ch;

	//このままでは通れない
	for(int i = 0; i < undef_index; i++){

		ch = NUM[undef[i]][index];
		if(type[ch] == UNDEFINED){
			if(IS_UPPER[undef[i]][index]){

				type[ch] = NO;

			}else{

				type[ch] = YES;
			}
			if(recursive(index+1)){

				return true;
			}
			if(IS_UPPER[undef[i]][index]){

				type[ch] = YES;

			}else{

				type[ch] = NO;
			}
		}
	}
	for(int i = 0 ; i < undef_index; i++){

		type[NUM[undef[i]][index]] = UNDEFINED;
	}

	return false;
}

void func(){

	for(int row = 0; row < 3; row++){

		scanf("%s",INPUT[row]);
	}

	is_OK = false;
	for(int i = 0; i < 26; i++){

		type[i] = UNDEFINED;
	}

	index_table = 0;
	for(int i = 0; i < M; i++){

		int base_col = 3*i;

		for(int state = 0; state < 8; state++){
			for(int row = 0; row < 3; row++){
				if(state & (1 << row)){

					table[row][index_table] = INPUT[row][base_col+1];

				}else{

					table[row][index_table] = INPUT[row][base_col+2];
				}
				IS_UPPER[row][index_table] = is_upper(table[row][index_table]);
				NUM[row][index_table] = get_num(table[row][index_table]);
			}
			index_table++;
		}
	}

	recursive(0);

	if(!is_OK){

		printf("-1\n");

	}else{

		vector<int> ANS;

		for(int loop = 0; loop < 26; loop++){
			if(ans_type[loop] == YES){
				ANS.push_back(loop);
			}
		}

		printf("%lld",ANS.size());

		for(int i = 0; i < ANS.size(); i++){

			printf(" %c",'A'+ANS[i]);
		}
		printf("\n");
	}
}

int main(){

	while(true){

		scanf("%d",&M);

		if(M == 0)break;

		func();
	}

	return 0;
}

