Problem: The committee members of the Kitoshima programming contest had decided to use crypto-graphic software for their secret communication. They had asked a company, Kodai Software, to develop cryptographic software that employed a cipher based on highly sophisticated mathematics.

According to reports on IT projects, many projects are not delivered on time, on budget, with required features and functions. This applied to this case. Kodai Software failed to implement the cipher by the appointed date of delivery, and asked to use a simpler version that employed a type of substitution cipher for the moment. The committee members got angry and strongly requested to deliver the full specification product, but they unwillingly decided to use this inferior product for the moment.

In what follows, we call the text before encryption, plaintext, and the text after encryption, ciphertext.

This simple cipher substitutes letters in the plaintext, and its substitution rule is specified with a set of pairs. A pair consists of two letters and is unordered, that is, the order of the letters in the pair does not matter. A pair (A, B) and a pair (B, A) have the same meaning. In one substitution rule, one letter can appear in at most one single pair. When a letter in a pair appears in the plaintext, the letter is replaced with the other letter in the pair. Letters not specified in any pairs are left as they are.

For example, by substituting the plaintext


ABCDEFGHIJKLMNOPQRSTUVWXYZ


with the substitution rule {(A, Z), (B, Y)} results in the following ciphertext.


ZYCDEFGHIJKLMNOPQRSTUVWXBA


This may be a big chance for us, because the substitution rule seems weak against cracking. We may be able to know communications between committee members. The mission here is to develop a deciphering program that finds the plaintext messages from given ciphertext messages.

A ciphertext message is composed of one or more ciphertext words. A ciphertext word is generated from a plaintext word with a substitution rule. You have a list of candidate words containing the words that can appear in the plaintext; no other words may appear. Some words in the list may not actually be used in the plaintext.

There always exists at least one sequence of candidate words from which the given ciphertext is obtained by some substitution rule. There may be cases where it is impossible to uniquely identify the plaintext from a given ciphertext and the list of candidate words.



Input

The input consists of multiple datasets, each of which contains a ciphertext message and a list of candidate words in the following format.

n
word1
.
.
.
wordn
sequence

n in the first line is a positive integer, representing the number of candidate words. Each of the next n lines represents one of the candidate words. The last line, sequence, is a sequence of one or more ciphertext words separated by a single space and terminated with a period.

You may assume the number of characters in each sequence is more than 1 and less than or equal to 80 including spaces and the period. The number of candidate words in the list, n, does not exceed 20. Only 26 uppercase letters, A to Z, are used in the words and the length of each word is from 1 to 20, inclusive.

A line of a single zero indicates the end of the input.

Output

For each dataset, your program should print the deciphered message in a line. Two adjacent words in an output line should be separated by a single space and the last word should be followed by a single period. When it is impossible to uniquely identify the plaintext, the output line should be a single hyphen followed by a single period.

Example

Input

4
A
AND
CAT
DOG
Z XUW ZVX Z YZT.
2
AZ
AY
ZA.
2
AA
BB
CC.
16
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
ABCDEFGHIJKLMNO
A B C D E F G H I J K L M N O ABCDEFGHIJKLMNO.
0


Output

A DOG AND A CAT.
AZ.
-.
A B C D E F G H I J K L M N O ABCDEFGHIJKLMNO.

Solution (in CPP):

Solution:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

char w1[22][110];
char w2[44][110];
int w1_cnt, w2_cnt;
int cw[28];
int aw[28];
bool ok[44][22];
int ok_cnt[44];
bool vis[44];
int ans;

bool cal_ok(int i, int j) {
    if (strlen(w2[i]) != strlen(w1[j])) return false;
    int tw[28];
    memcpy(tw, cw, sizeof(tw));
    for (int k = 0; w2[i][k]; k++) {
        int c = w2[i][k] - 'A';
        int d = w1[j][k] - 'A';
        if (tw[c] != -1 && tw[c] != w1[j][k]) return false;
        if (tw[d] != -1 && tw[d] != w2[i][k]) return false;
        tw[c] = w1[j][k];
        tw[d] = w2[i][k];
    }
    return true;
}
void get_ok() {
    memset(ok, 0, sizeof(ok));
    for (int i = 0; i < w2_cnt; i++)
        for (int j = 0; j < w1_cnt; j++) {
            ok[i][j] = cal_ok(i, j);
            if (ok[i][j]) ok_cnt[i]++;
        }
}
void print_ok() {
	for (int i = 0; i < w2_cnt; i++) {
		for (int j = 0; j < w1_cnt; j++) {
			printf("%d ", ok[i][j]);
		}
		puts("");
	}
}

int find() {
    int p = -1;
    for (int i = 0; i < w2_cnt; i++) if (!vis[i])
        if (p == -1 || ok_cnt[i] < ok_cnt[p]) p = i;
    return p;
}

void dfs(int u) {
    if (ans > 1) return;
    if (u == -1) {
        ans++;
        memcpy(aw, cw, sizeof(aw));
        return;
    }
//    bool tmp[44][22];
//    int tmp_cnt[44];
    int tw[28];
//    memcpy(tmp, ok, sizeof(tmp));
//    memcpy(tmp_cnt, ok_cnt, sizeof(ok_cnt));
    memcpy(tw, cw, sizeof(tw));
    get_ok();
    for (int i = 0; i < w1_cnt; i++) if (ok[u][i]) {
        vis[u] = true;
        for (int j = 0; w2[u][j]; j++) {
            int c = w2[u][j] - 'A';
            int d = w1[i][j] - 'A';
            cw[c] = w1[i][j];
            cw[d] = w2[u][j];
        }
        dfs(find());
        memcpy(cw, tw, sizeof(tw));
        vis[u] = false;
        get_ok();
//        memcpy(ok_cnt, tmp_cnt, sizeof(tmp_cnt));
//        memcpy(ok, tmp, sizeof(tmp));
    }
}

void work() {
    for (int i = 0; i < w1_cnt; i++)
        scanf("%s", w1[i]);
    w2_cnt = 0;
    while (true) {
        char str[100];
        scanf("%s", str);
        int len = strlen(str);
        if (str[len - 1] == '.') {
            str[--len] = 0;
            strcpy(w2[w2_cnt], str);
            w2_cnt++;
            break;
        } else {
            strcpy(w2[w2_cnt], str);
            w2_cnt++;
        }
    }
//for (int i = 0; i < w2_cnt; i++) printf("%s ", w2[i]); puts(".....");
    memset(cw, -1, sizeof(cw));
    get_ok();
//print_ok();
    memset(vis, 0, sizeof(vis));
    int p = find();
//printf("%d\n", p);
    ans = 0;
    dfs(p);
    if (ans > 1) {
        puts("-.");
        return;
    }
//for (int i = 0; i < 26; i++) printf("%d ", aw[i]); puts("?");
    for (int i = 0; i < w2_cnt; i++) {
        for (int j = 0; w2[i][j]; j++) {
            int d = w2[i][j] - 'A';
            printf("%c", aw[d]);
        }
        if (i < w2_cnt - 1) printf(" ");
    }
    puts(".");
}

int main() {
    while (scanf("%d", &w1_cnt), w1_cnt) {
        work();
    }
    return 0;
}