#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, bool upper) {
  if (pos >= n || (!lower && !upper)) return true;
  if (ans[s[pos] - 'a'] != -1) {
    if (lower && ans[s[pos] - 'a'] < a[pos]) return false;
    if (upper && ans[s[pos] - 'a'] > b[pos]) return false;
    return dfs(pos + 1, lower && (ans[s[pos] - 'a'] == a[pos]),
               upper && (ans[s[pos] - 'a'] == b[pos]));
  } else {
    for (int j = 0; j < k; ++j) {
      if (vis[j]) continue;
      if (lower && j < a[pos] - 'a') continue;
      if (upper && j > b[pos] - 'a') continue;
      vis[j] = 1;
      ans[s[pos] - 'a'] = j + 'a';
      if (dfs(pos + 1, lower && (ans[s[pos] - 'a'] == a[pos]),
              upper && (ans[s[pos] - 'a'] == b[pos])))
        return true;
      vis[j] = 0;
      ans[s[pos] - 'a'] = -1;
    }
  }
  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, -1, sizeof(ans));
    if (!dfs(0, true, true)) {
      cout << "NO" << endl;
      continue;
    }
    int j = 0;
    for (int i = 0; i < k; ++i) {
      if (ans[i] == -1) {
        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;
}
