#include <bits/stdc++.h>
using namespace std;
string s, a, b;
int n, k;
int t;
bool vis[26];
int ans[26];
bool dfs(int pos, bool lower_bnd, bool upper_bnd) {
  if (pos >= n || (!lower_bnd && !upper_bnd)) return true;
  int x = s[pos] - 'a';
  if (ans[x]) {
    if (lower_bnd && ans[x] < a[pos]) return false;
    if (upper_bnd && ans[x] > b[pos]) return false;
    return dfs(pos + 1, lower_bnd && (ans[x] == a[pos]),
               upper_bnd && (ans[x] == b[pos]));
  } else {
    for (int j = 0; j < k; ++j) {
      if (vis[j]) continue;
      if (lower_bnd && j + 'a' < a[pos]) continue;
      if (upper_bnd && j + 'a' > b[pos]) continue;
      vis[j] = true;
      ans[x] = j + 'a';
      if (dfs(pos + 1, lower_bnd && (ans[x] == a[pos]),
              upper_bnd && (ans[x] == b[pos])))
        return true;
      vis[j] = false;
      ans[x] = 0;
    }
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> t;
  while (t--) {
    cin >> k;
    cin >> s >> a >> b;
    n = s.length();
    memset(vis, 0, sizeof(vis));
    memset(ans, 0, sizeof(ans));
    if (!dfs(0, true, true)) {
      cout << "NO" << endl;
      continue;
    }
    int j = 0;
    for (int i = 0; i < k; ++i) {
      if (!ans[i]) {
        while (vis[j]) j++;
        ans[i] = j + 'a';
        vis[j] = 1;
      }
    }
    cout << "YES\n";
    for (int i = 0; i < k; ++i) cout << char(ans[i]);
    cout << "\n";
  }
  return 0;
}
