#include <bits/stdc++.h> using namespace std; typedef long long ll; #ifdef DEBUG #define var(x) cerr << #x << ": " << x << '\n'; #define range(a, b) cerr << #a <<", " << #b << ": "; for (auto _it = a; _it != b; ++_it) cerr << *_it << ' '; cerr <<'\n'; #else #define cerr if (false) cerr #define var(x) #define range(a, b) #endif #define pii pair<int, int> #define F first #define S second #define T(x, i) get<i>(x) #define all(v) v.begin(), v.end() #define forn(i, n) for (int i = 0; i < n; i++) const int MAXN = 1e6 + 10; int n; string s[MAXN]; string t; void solve() { set<int> active; forn(i, n) { cin >> s[i]; active.insert(i); } cin >> t; vector<int> ptr(n, 0); string res; vector<int> todel; forn(i, t.size()) { for (auto idx : active) { while (ptr[idx] < s[idx].size() && s[idx][ptr[idx]] != t[i]) { res.push_back(s[idx][ptr[idx]]); ptr[idx]++; } if (ptr[idx] == s[idx].size()) { todel.push_back(idx); } } while (todel.size()) { active.erase(todel.back()); todel.pop_back(); } if (active.size() == 0) break; res.push_back(t[i]); for (auto idx : active) { // while (ptr[idx] < s[idx].size() && s[idx][ptr[idx]] != t[i]) { // res.push_back(s[idx][ptr[idx]]); ptr[idx]++; // } if (ptr[idx] == s[idx].size()) { todel.push_back(idx); } } while (todel.size()) { active.erase(todel.back()); todel.pop_back(); } if (i + 1 == t.size()) { cout << "NO\n"; return; } } cout << "YES\n"; cout << res << '\n'; } signed main() { #ifdef DEBUG freopen("input.in", "r", stdin); freopen("output.out", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); while (cin >> n) solve(); }