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 <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<char, char> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

int n,m;
string w[20];
vector<string> s;
vector<int> ord;
int res=0;
set<P> role[2];
bool used[26];
int ccnt[100];

void dfs(int i){
  if(i==m){
    res++;
    if(res<2){
      role[res]=role[res-1];
    }
    return ;
  }
  int j=ord[i];
  rep(k,n){
    if(w[k].size()>s[j].size())break;
    if(s[j].size()!=w[k].size())continue;
    bool ok=true;
    vector<P> add;
    rep(l,s[j].size()){
      char c1=s[j][l],c2=w[k][l];
      if(used[c1-'A']!=used[c2-'A']){
        ok=false; break;
      }
      if(used[c1-'A']&&used[c2-'A']&&role[res].find(P(c1,c2))==role[res].end()){
        ok=false; break;
      }
      if(role[res].find(P(c1,c2))==role[res].end()){
        role[res].insert(P(c1,c2)); role[res].insert(P(c2,c1));
        used[c1-'A']=used[c2-'A']=true;
        add.push_back(P(c1,c2));
      }
    }
    if(!ok){
      rep(l,add.size()){
        role[res].erase(P(add[l].fi,add[l].se));
        role[res].erase(P(add[l].se,add[l].fi));
        used[add[l].fi-'A']=false; used[add[l].se-'A']=false;
      }
      continue;
    }
    dfs(i+1);
    if(res==2)return;
    rep(l,add.size()){
      role[res].erase(P(add[l].fi,add[l].se));
      role[res].erase(P(add[l].se,add[l].fi));
      used[add[l].fi-'A']=false; used[add[l].se-'A']=false;
    }
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  while(1){
    cin>>n;
    if(n==0)break;
    s.clear();
    m=0; ord.clear();
    rep(i,n)cin>>w[i];
    sort(w,w+n,[](const string& a,const string& b){ return a.size() < b.size(); });
    while(1){
      ord.push_back(m++);
      string tmp;
      cin>>tmp;
      if(tmp[tmp.size()-1]=='.'){
        s.push_back(tmp.substr(0,tmp.size()-1));
        break;
      }
      s.push_back(tmp);
    }
    rep(i,m){
      set<char> st;
      rep(j,s[i].size())st.insert(s[i][j]);
      ccnt[i]=st.size();
    }
    sort(all(ord),[=](const int& a,const int& b){ return ccnt[a] > ccnt[b]; });
    res=0;
    rep(i,2)role[i].clear();
    memset(used,0,sizeof(used));
    dfs(0);
    if(res==2)cout<<"-."<<endl;
    else{
      string ans=s[0];
      repl(i,1,m)ans+=" "+s[i];
      ans+=".";
      rep(i,ans.size()){
        for(P p : role[0]){
          if(ans[i]==p.fi){
            ans[i]=p.se;
            break;
          }
        }
      }
      cout<<ans<<endl;
    }
  }
  return 0;
}