#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = a; i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int) (x).size() typedef long long ll; typedef pair<int, int> pi; typedef vector<int> vi; int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); int n; cin >> n; vector <string> v(n); for (auto &x : v) cin >> x; string t, ans = ""; cin >> t; vector <stack <int>> cnt(555); for (int i = 0; i < n; i++) { cnt[v[i][0]].push(i); } vector <int> pntr(n + 1, 0); vector <stack <int>> nxt(555); int pool = n; while (pool) { int best = -1; for (char c = 'a'; c <= 'z'; c++) { if (c != t[pntr[n]] && cnt[c].size() > 0) { if (best == -1 || cnt[best].size() < cnt[c].size()) { best = c; } } } if (best == -1) { ans += t[pntr[n]]; while (cnt[t[pntr[n]]].size()) { int cur = cnt[t[pntr[n]]].top(); cnt[t[pntr[n]]].pop(); pntr[cur]++; if (pntr[cur] < v[cur].size()) { nxt[v[cur][pntr[cur]]].push(cur); } else pool--; } for (char c = 'a'; c <= 'z'; c++) { while (nxt[c].size()) { int cur = nxt[c].top(); nxt[c].pop(); cnt[v[cur][pntr[cur]]].push(cur); } } pntr[n]++; if (pntr[n] == t.size()) { cout << "NO\n"; return 0; } } else { ans += char(best); while (cnt[best].size()) { int cur = cnt[best].top(); cnt[best].pop(); pntr[cur]++; if (pntr[cur] < v[cur].size()) { nxt[v[cur][pntr[cur]]].push(cur); } else pool--; } for (char c = 'a'; c <= 'z'; c++) { while (nxt[c].size()) { int cur = nxt[c].top(); nxt[c].pop(); cnt[v[cur][pntr[cur]]].push(cur); } } } } cout << "YES\n"; cout << ans << '\n'; }