#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstring>
#include <sstream>
using namespace std;

int n, m;
string cand[22];
vector<string> words;

vector<int> match[82];
int matchBit[82];

vector<char> ansKey;
int ansFlg;

bool matches(string a, string b){
  if(a.size() != b.size()) return false;
  char trans[128];
  memset(trans, -1, sizeof(trans));
  for(int i = 0; i < a.size(); i++){
    if(trans[a[i]] != -1 && b[i] != trans[a[i]]) return false;
    if(trans[b[i]] != -1 && a[i] != trans[b[i]]) return false;
    trans[a[i]] = b[i];
    trans[b[i]] = a[i];
  }
  return true;
}

bool mycmp(const string &a, const string &b){
  set<char> st1;
  for(int i = 0; i < a.size(); i++) st1.insert(a[i]);
  set<char> st2;
  for(int i = 0; i < b.size(); i++) st2.insert(b[i]);

  return st1.size() > st2.size();
}

bool setKey(const string &a, const string &b, vector<char> &key){
  for(int i = 0; i < a.size(); i++){
    if(key[a[i]] != -1 && key[a[i]] != b[i] ||
       key[b[i]] != -1 && key[b[i]] != a[i]){
      return false;
    }
    key[a[i]] = b[i];
    key[b[i]] = a[i];
  }
  return true;
}

void dfs(int idx, int used, vector<char> key){
  if(idx == m){
    if(ansFlg == 1){
      ansFlg = -1;
    }
    else{
      ansFlg = 1;
      ansKey = key;
    }
    return;
  }

  for(int i = 0; i < match[idx].size(); i++){
    int j = match[idx][i];
    if(used & (1 << j)) continue;

    vector<char> nextKey = key;
    if(setKey(words[idx], cand[j], nextKey)){
      dfs(idx + 1, used | (1 << j), nextKey);
      if(ansFlg == -1) return;
    }
  }
}

void solve(){
  sort(words.begin(), words.end(), mycmp);

  for(int i = 0; i < m; i++){
    match[i].clear();
    matchBit[i] = 0;

    for(int j = 0; j < n; j++){
      if(matches(words[i], cand[j])){
        match[i].push_back(j);
        matchBit[i] |= (1 << j);
      }
    }
  }

  vector<char> key(128, -1);
  ansFlg = 0;
  dfs(0, 0, key);
}

int main(){
  while(cin >> n, n){
    for(int i = 0; i < n; i++){
      cin >> cand[i];

      for(int j = 0; j < i; j++){
        if(cand[j] == cand[i]){
          i--;
          n--;
          break;
        }
      }
    }

    string s;
    getline(cin, s);
    getline(cin, s);
    for(int i = 0; i < s.size(); i++) if(s[i] == '.') s[i] = ' ';

    vector<string> raw;
    stringstream ss(s);
    words.clear();

    while(ss >> s){
      raw.push_back(s);

      bool pushFlg = true;
      for(int i = 0; i < words.size(); i++){
        if(words[i] == s){
          pushFlg = false;
          break;
        }
      }
      if(pushFlg) words.push_back(s);
    }
    m = words.size();

    solve();

    if(ansFlg == 1){
      for(int i = 0; i < raw.size(); i++){
        if(i != 0) cout << " ";
        for(int j = 0; j < raw[i].size(); j++){
          cout << ansKey[raw[i][j]];
        }
      }
      cout << "." << endl;
    }
    else{
      cout << "-." << endl;
    }
  }
}