#include <bits/stdc++.h>
using namespace std;
void Print(string s) {
  cout << "YES\n";
  vector<bool> taken(256, false);
  int n = s.size();
  for (int i = 0; i < n; i++) {
    if (s[i] != '-') taken[(int)s[i]] = true;
  }
  char nxt = 'a';
  for (int i = 0; i < n; i++) {
    if (s[i] == '-') {
      while (taken[(int)nxt]) nxt++;
      taken[(int)nxt] = true;
      s[i] = nxt;
    }
  }
  cout << s << "\n";
}
void solve() {
  int k;
  string s, a, b;
  cin >> k >> s >> a >> b;
  string change_to;
  for (int i = 0; i < k; i++) change_to += "-";
  vector<bool> taken(256, false);
  int n = s.size();
  bool prefixOk = true;
  int pr = 0;
  while (pr < n && a[pr] == b[pr]) {
    if (change_to[s[pr] - 'a'] == '-') {
      if (taken[(int)a[pr]]) {
        prefixOk = false;
        break;
      }
      change_to[s[pr] - 'a'] = a[pr];
      taken[(int)a[pr]] = true;
    }
    if (change_to[s[pr] - 'a'] != a[pr]) {
      prefixOk = false;
      break;
    }
    pr++;
  }
  if (!prefixOk) {
    cout << "NO\n";
    return;
  }
  if (pr == n) {
    Print(change_to);
    return;
  }
  char L = 'a';
  char R = 'a' + k - 1;
  if (change_to[s[pr] - 'a'] != '-') {
    L = change_to[s[pr] - 'a'];
    R = change_to[s[pr] - 'a'];
  }
  for (char c = L; c <= R; c++) {
    if (taken[c] && change_to[s[pr] - 'a'] != c) continue;
    if (c < a[pr] || c > b[pr]) continue;
    string old_change_to = change_to;
    vector<bool> old_taken = taken;
    change_to[s[pr] - 'a'] = c;
    taken[c] = true;
    bool ok = true;
    if (change_to[s[pr] - 'a'] == a[pr]) {
      for (int i = pr + 1; i < n; i++) {
        if (change_to[s[i] - 'a'] == '-') {
          for (char tr = 'a' + k - 1; tr >= 'a'; tr--) {
            if (taken[tr]) continue;
            change_to[s[i] - 'a'] = tr;
            taken[tr] = true;
            break;
          }
        }
        if (change_to[s[i] - 'a'] == '-' || change_to[s[i] - 'a'] < a[i]) {
          ok = false;
          break;
        }
        if (change_to[s[i] - 'a'] > a[i]) break;
      }
    } else if (change_to[s[pr] - 'a'] == b[pr]) {
      for (int i = pr + 1; i < n; i++) {
        if (change_to[s[i] - 'a'] == '-') {
          for (char tr = 'a'; tr <= 'a' + k - 1; tr++) {
            if (taken[tr]) continue;
            change_to[s[i] - 'a'] = tr;
            taken[tr] = true;
            break;
          }
        }
        if (change_to[s[i] - 'a'] == '-' || change_to[s[i] - 'a'] > b[i]) {
          ok = false;
          break;
        }
        if (change_to[s[i] - 'a'] < b[i]) break;
      }
    }
    if (ok) {
      Print(change_to);
      return;
    }
    change_to = old_change_to;
    taken = old_taken;
  }
  cout << "NO\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    solve();
  }
}
