//Name: Weaker then Planned
//Level:
//Category:
//Note:

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <array>
#include <map>
#include <set>

using namespace std;

#define TIMES(i,n) for(int i = 0; i < (n); ++i)

typedef array<char,256> Table;
Table table, ans;
bool found = false;

bool check(const vector<string> &words, const vector<string> &crypted) {
    for(const string &cs : crypted) {
        for(const string &w : words) {
            if(cs.size() != w.size()) continue;
            bool ok = true;
            TIMES(i, cs.size()) {
                const char cch = cs[i];
                const char wch = w[i];
                if(table[cch] != 0 && table[cch] != wch) {
                    ok = false;
                    break;
                }
            }
            if(ok) goto next_cs;
        }
        //cout << "no match for " << cs << endl;
        return false;
next_cs:
        ;
    }
    return true;
}

bool search(int pos, const vector<string> &words, const vector<string> &crypted) {
    if(pos == crypted.size()) {
        if(found) throw "ambiguous";
        found = true;
        ans = table;
        return true;
    }

    const string &cs = crypted[pos];
    for(const string &w : words) {
        if(w.size() != cs.size()) continue;
        Table bak = table;
        TIMES(i, w.size()) {
            const char cch = cs[i];
            const char wch = w[i];
            // Check whether consistency
            if(table[cch] != 0 && table[cch] != wch) {
                goto next;
            }
            if(table[wch] != 0 && table[wch] != cch) {
                goto next;
            }
            table[cch] = wch;
            table[wch] = cch;
        }
        //cout << cs << ' ' << w << endl;
        // Check consistency for other words
        if(!check(words, crypted)) goto next;
        search(pos+1, words, crypted);
next:
        table = bak;
    }
    return false;
}

bool solve() {
    int N;
    cin >> N;
    if(!N) return false;

    vector<string> words(N);
    TIMES(i, N) {
        cin >> words[i];
    }
    vector<string> seq;
    while(true) {
        string w;
        cin >> w;
        if(w[w.size()-1] == '.') {
            seq.push_back(w.substr(0, w.size()-1));
            break;
        } else {
            seq.push_back(w);
        }
    }
    vector<pair<int,string>> v;
    TIMES(i, seq.size()) {
        const auto &s = seq[i];
        vector<bool> seen(26, false);
        int cnt = 0;
        for(char c : s) {
            if(seen[c-'A']) continue;
            seen[c-'A'] = true;
            ++cnt;
        }
        v.push_back(make_pair(i, s));
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    reverse(v.begin(), v.end());

    vector<string> crypted;
    for(const auto &p : v) {
        crypted.push_back(p.second);
    }
    fill(table.begin(), table.end(), 0);
    found = false;
    try {
        search(0, words, crypted);
    } catch(const char *s) {
        found = false;
    }
    if(found) {
        bool first = true;
        for(const string &s : seq) {
            if(!first) cout << ' ';
            for(char c : s) {
                cout << ans[c];
            }
            first = false;
        }
        cout << '.' << endl;
    } else {
        cout << "-." << endl;
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 1300