#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

#define MAX_WLEN	(20)

/* typedef */

typedef vector<int> vi;
typedef vector<string> vs;

class LessWord {
public:
  bool operator()(const string& w0, const string& w1) const {
    return w1.size() < w0.size() || (w1.size() == w0.size() && w0 < w1);
  }
};

/* global variables */

int nus;
int tbl[26];
string ptxt;
vs seq, useq, words[MAX_WLEN + 1];

/* subroutines */

string dcword(string& w) {
  //cout << "dcword:" << w << endl;
  string dcw = string();

  for (int i = 0; i < w.size(); i++)
    dcw += tbl[w[i] - 'A'] + 'A';

  return dcw;
}

void decipher(int k) {
  //cout << "decipher:" << k << endl;
  if (k >= nus) {
    if (ptxt == "") {
      for (int i = 0; i < seq.size(); i++) {
	if (i > 0) ptxt += ' ';
	ptxt += dcword(seq[i]);
      }
      return;
    }
    ptxt = "-";
    return;
  }

  string& usw = useq[k];
  int uslen = usw.size();
  vi rpl;

  for (int i = 0; i < words[uslen].size(); i++) {
    string& word = words[uslen][i];
    int ok = 1;
    rpl.clear();
    
    for (int j = 0; j < uslen; j++) {
      int uswj = usw[j] - 'A';
      int wj = word[j] - 'A';
      if (tbl[uswj] < 0 && tbl[wj] < 0) {
        rpl.push_back(uswj);
        rpl.push_back(wj);
        tbl[uswj] = wj;
	tbl[wj] = uswj;
      }
      else if (tbl[uswj] != wj) {
        ok = 0;
        break;
      }
    }

    if (ok) {
      decipher(k + 1);
      if (ptxt == "-") return;
    }

    for (vi::iterator vit = rpl.begin(); vit < rpl.end(); vit++)
      tbl[*vit] = -1;
  }
}

/* main */

int main() {
  int n;

  for (;;) {
    cin >> n;
    if (n == 0) break;

    for (int i = 0; i <= MAX_WLEN; i++)
      words[i].clear();
    
    for (int i = 0; i < n; i++) {
      string w = string();
      cin >> w;
      //cout << w << endl;
      words[w.size()].push_back(w);
    }
    //for (int i = 0; i <= MAX_WLEN; i++) cout << words[i].size() << endl;
    
    seq.clear();
    for (;;) {
      string w = string();
      cin >> w;
      //cout << w << endl;
      string::size_type loc = w.find('.', 0);
      if (loc != string::npos) {
	w.erase(loc);
	seq.push_back(w);
	break;
      }
      seq.push_back(w);
    }
    //for (int i = 0; i < seq.size(); i++) cout << seq[i] << endl;

    set<string> seqset = set<string>(seq.begin(), seq.end());
    useq = vs(seqset.begin(), seqset.end());
    sort(useq.begin(), useq.end(), LessWord());
    nus = useq.size();
    //for (int i = 0; i < nus; i++) cout << useq[i] << endl;
    //  #p $words
    //  #p $useq

    for (int i = 0; i < 26; i++) tbl[i] = -1;
    ptxt = "";

    decipher(0);

    cout << ptxt << '.' << endl;
  }

  return 0;
}