#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <sstream>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct String {
  string s;
  String() {;}
  String(string s) : s(s) {;}
  int CalcKind() const {
    int exist[300];
    MEMSET(exist, 0);
    FORIT(it, s) { exist[(int)*it] = 1; }
    int ret = 0;
    REP(i, 300) { ret += exist[i]; }
    return ret;
  }
  bool operator<(const String &rhs) const {
    if (CalcKind() != rhs.CalcKind()) { return CalcKind() > rhs.CalcKind(); }
    return s < rhs.s;
  }
};

int cnt;
int n;
int perm[200];
char word[30][100];
char str[1000];
char ans[1000];
vector<String> strs;

int calc(int depth) {
  if (depth == (int)strs.size()) {
    int len = strlen(str);
    REP(i, len) {
      assert(str[i] != -1);
      ans[i] = perm[(int)str[i]];
    }
    ans[len] = 0;
    cnt++;
    return cnt;
  }
  const string s = strs[depth].s;
  REP(i, n) {
    if (strlen(word[i]) != s.size()) { continue; }
    int pperm[200];
    memcpy(pperm, perm, sizeof(perm));
    REP(j, s.size()) {
      int l = s[j];
      int r = word[i][j];
      if (perm[l] == r && perm[r] == l) {
        ;
      } else if (perm[l] == -1 && perm[r] == -1) {
        perm[l] = r;
        perm[r] = l;
      } else {
        goto next;
      }
    }
    calc(depth + 1);
    if (cnt >= 2) { return cnt; }
next:;
     memcpy(perm, pperm, sizeof(perm));
  }
  return cnt;
}

int main() {
  while (scanf("%d", &n), n) {
    cnt = 0;
    strs.clear();
    MEMSET(perm, -1);
    MEMSET(word, 0);
    perm[' '] = ' ';
    perm['.'] = '.';
    REP(i, n) {
      scanf("%s", word[i]);
      REP(j, i) {
        if (strcmp(word[i], word[j]) == 0) { i--; n--; break; }
      }
    }
    fgets(str, 999, stdin);
    fgets(str, 999, stdin);
    str[strlen(str) - 1] = 0;
    memcpy(ans, str, sizeof(ans));
    {
      stringstream sin(str);
      string s;
      while (sin >> s) {
        if (*s.rbegin() == '.') { s = s.substr(0, s.size() - 1); }
        strs.push_back(String(s));
      }
      sort(strs.begin(), strs.end());
    }
    if (calc(0) == 1) {
      printf("%s\n", ans);
    } else {
      printf("-.\n");
    }
  }
}