#include <set>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdio>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

const int NONE = 0;

struct table{
  vector<char> t;
  table() : t(26, NONE) {}

  bool addRule(char a, char b){
    if(t[a - 'A'] != NONE && t[a - 'A'] != b) return false;
    if(t[b - 'A'] != NONE && t[b - 'A'] != a) return false;

    t[a - 'A'] = b;
    t[b - 'A'] = a;
    return true;
  }
};

inline bool operator < (const table &lhs, const table &rhs){
  return lhs.t < rhs.t;
}

pair<bool, table> merge(const table &a, const table &b){
  table t;
  bool  o = true;

  REP(i, 26){
    if(a.t[i] == b.t[i]){
      t.t[i] = a.t[i];
    }else{
      if(a.t[i] == NONE)
        t.t[i] = b.t[i];
      else if(b.t[i] == NONE)
        t.t[i] = a.t[i];
      else{
        o = false;
        break;
      }
    }
  }

  return make_pair(o, t);
}

bool ok[20][40];
vector<vector<table> > t;
vector<int> anseq(40);
vector<int> ans;
vector<set<table> > memo;

vector<string> _seq;
vector<string> _word;

int n, m;

void dfs(int pos, int flag, table tbl){
  if(pos == m){
    if(ans.size()) throw 0;
    ans = anseq;
  }else{
    if(memo[pos].find(tbl) != memo[pos].end())
      return;
    memo[pos].insert(tbl);

    // printf("pos = %d\n", pos);

    REP(i,n) if(ok[i][pos] && (flag & (1 << i)) == 0){
      pair<bool, table> ret = merge(tbl, t[i][pos]);
      // printf("%s -> %s : %d\n", _seq[pos].c_str(), _word[i].c_str(), ret.first);
      if(ret.first){
        anseq[pos] = i;
        dfs(pos + 1, (flag | (1 << i)), ret.second);
      }
    }
  }
}

struct cmp{
  bool operator () (const string &lhs, const string &rhs){
    return lhs.size() > rhs.size();
  }
};

int main(){
  while(cin >> n, n){
    vector<string> word(n);
    vector<string> oseq;
    vector<string> seq;
    REP(i, n) cin >> word[i];

    while(true){
      string tmp; cin >> tmp;
      if(tmp.find(".") != string::npos){
        tmp = tmp.substr(0, tmp.size() - 1);
        seq.push_back(tmp);
        break;
      }
      seq.push_back(tmp);
    }

    oseq = seq; // save original sequence

    sort(seq.begin(), seq.end());
    seq.erase(unique(seq.begin(), seq.end()), seq.end());

    sort(seq.begin(), seq.end(), cmp());

    m = seq.size();
    t = vector<vector<table> >(n, vector<table>(m));

    REP(i,n) REP(j,m){
      if(word[i].size() == seq[j].size()){
        int len = word[i].size();
        bool tmp = true;

        REP(k, len){
          char a = word[i][k];
          char b = seq[j][k];

          if(!t[i][j].addRule(a, b)){
            tmp = false;
            break;
          }
        }
        ok[i][j] = tmp;
      }else{
        ok[i][j] = false;
      }
    }

    ans = vector<int>();
    memo = vector<set<table> >(m);

    try{
      _seq  = seq;
      _word = word;

      dfs(0, 0, table());

      REP(i, oseq.size()){
        REP(j, m){
          if(oseq[i] == seq[j]){
            cout << word[ans[j]];
            break;
          }
        }
        if(i == oseq.size() - 1)
          cout << "." << endl;
        else
          cout << " ";
      }
    }catch(int e){
      cout << "-." << endl;
    }

  }
  return 0;
}

Measured memory_bytes: 0