#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;


#define NUM 21

void strcpy(char* to,char* str);

struct Info{
	Info(char arg_word[NUM],int arg_length){
		strcpy(word,arg_word);
		length = arg_length;
	}
	bool operator<(const struct Info &arg) const{
		return length > arg.length;
	}
	char word[NUM];
	int length;
};


int N;
int num_finish;
int num_word[NUM];
char sequence[100];
char table[26],ans_table[26];
char plain_word[NUM][20][NUM];
vector<Info> V;


bool strCmp(char* base, char* comp){
	int length1,length2;
	for(length1=0;base[length1] != '\0';length1++);
	for(length2=0;comp[length2] != '\0';length2++);
	if(length1 != length2)return false;

	for(int i=0;base[i] != '\0'; i++){
		if(base[i] != comp[i])return false;
	}
	return true;
}

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

int getNUM(char ch){
	return ch-'A';
}

void recursive(int index){

	if(num_finish >= 2){
		return;
	}

	if(index == V.size()){

		num_finish++;
		for(int i = 0; i < 26; i++){
			ans_table[i] = table[i];
		}

		return;
	}

	int tmp_len;
	char tmp_ch;
	bool FLG,is_match;

	for(int i = index; i < V.size(); i++){

		tmp_len = V[i].length;

		FLG = false;

		for(int k = 0; k < num_word[tmp_len]; k++){

			is_match = true;
			for(int loc = 0; loc < tmp_len; loc++){

				tmp_ch = table[getNUM(V[i].word[loc])];

				if((V[i].word[loc] == plain_word[tmp_len][k][loc] && tmp_ch == '?') ||
						(tmp_ch == '?' && table[getNUM(plain_word[tmp_len][k][loc])] == '?') ||
						(tmp_ch == plain_word[tmp_len][k][loc])
						){
					continue;
				}else{
					is_match = false;
					break;
				}
			}
			if(is_match){
				FLG = true;
				break;
			}
		}
		if(!FLG){
			return;
		}
	}

	char work[26];

	tmp_len = V[index].length;

	for(int i = 0; i < num_word[tmp_len]; i++){

		for(int k = 0; k < 26; k++){
			work[k] = table[k];
		}

		is_match = true;

		for(int k = 0; k < tmp_len; k++){

			if((tmp_ch = table[getNUM(V[index].word[k])]) != '?'){

				if(tmp_ch != plain_word[tmp_len][i][k]){
					is_match = false;
					break;
				}

			}else{

				if(table[getNUM(plain_word[tmp_len][i][k])] != '?'){
					is_match = false;
					break;
				}

				table[getNUM(V[index].word[k])] = plain_word[tmp_len][i][k];
				table[getNUM(plain_word[tmp_len][i][k])] = V[index].word[k];
			}
		}

		if(is_match){
			recursive(index+1);
		}

		for(int k = 0; k < 26; k++){
			table[k] = work[k];
		}
	}
}

bool is_char(char ch){
	return ch >= 'A' && ch <= 'Z';
}

void func(){

	V.clear();

	for(int i = 0; i < NUM; i++){
		num_word[i] = 0;
	}

	char buf[NUM];
	int length;

	for(int loop = 0; loop < N; loop++){

		scanf("%s",buf);
		for(length = 0; buf[length] != '\0' && length < 81; length++);

		strcpy(plain_word[length][num_word[length]++],buf);
	}

	getchar();
	fgets(sequence,100,stdin);

	char work[NUM];
	int start,work_index;

	for(int i = 0; sequence[i] != '\0'; ){

		start = i;
		while(sequence[start] == ' ')start++;

		work_index = 0;

		while(is_char(sequence[start+work_index])){

			work[work_index] = sequence[start+work_index];
			work_index++;
		}
		work[work_index] = '\0';

		V.push_back(Info(work,work_index));

		if(sequence[start+work_index] == '.'){
			break;
		}
		i = start+work_index;
	}

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

	for(int i = 0; i < 26; i++){
		table[i] = '?';
	}

	num_finish = 0;
	recursive(0);

	if(num_finish != 1){

		printf("-.\n");

	}else{
		int loc;

		for(int i = 0; sequence[i] != '\0' && i < 100; i++){

			if(!is_char(sequence[i])){

				printf("%c",sequence[i]);

			}else{

				loc = getNUM(sequence[i]);

				if(ans_table[loc] == '?'){ //そのまま

					printf("%c",sequence[i]);

				}else{

					printf("%c",ans_table[loc]);
				}
			}
		}
	}
}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}



Measured memory_bytes: 3176