#include <bits/stdc++.h>
using namespace std;
signed main1() {
  string s, a, b;
  long long k;
  cin >> k >> s >> a >> b;
  long long n = s.size();
  vector<char> is(k);
  vector<bool> used(k);
  for (long long i = 0; i < k; i++) {
    is[i] = '0';
  }
  long long last = n;
  for (long long i = 0; i < n; i++) {
    if (a[i] != b[i]) {
      if (a[i] > b[i]) {
        cout << "NO\n";
        return 0;
      }
      last = i;
      break;
    }
    long long code = a[i] - 'a';
    if (is[s[i] - 'a'] == '0') {
      if (used[code]) {
        cout << "NO\n";
        return 0;
      }
      used[code] = 1;
      is[s[i] - 'a'] = a[i];
    }
    if (is[s[i] - 'a'] != a[i]) {
      cout << "NO\n";
      return 0;
    }
  }
  bool morea = 0, lessb = 0;
  while (last < n && is[s[last] - 'a'] != '0') {
    if (is[s[last] - 'a'] > a[last]) {
      morea = 1;
    } else if (!morea && is[s[last] - 'a'] < a[last]) {
      cout << "NO\n";
      return 0;
    }
    if (is[s[last] - 'a'] < b[last]) {
      lessb = 1;
    } else if (!lessb && is[s[last] - 'a'] > b[last]) {
      cout << "NO\n";
      return 0;
    }
    last++;
  }
  if (last != n && !morea && !lessb) {
    bool found = 0;
    for (long long c = a[last] - 'a' + 1; c < b[last] - 'a'; c++) {
      if (!used[c]) {
        used[c] = 1;
        is[s[last] - 'a'] = c + 'a';
        found = 1;
        break;
      }
    }
    if (!found) {
      bool can = 0;
      if (!used[a[last] - 'a']) {
        used[a[last] - 'a'] = 1;
        is[s[last] - 'a'] = a[last];
        can = 1;
        vector<long long> clearus;
        vector<long long> clearis;
        clearis.push_back(s[last] - 'a');
        clearus.push_back(a[last] - 'a');
        for (long long i = last + 1; i < n; i++) {
          if (is[s[i] - 'a'] != '0') {
            if (is[s[i] - 'a'] < a[i]) {
              can = 0;
              break;
            } else if (is[s[i] - 'a'] > a[i]) {
              break;
            }
          } else {
            bool fl = 0;
            for (long long j = a[i] - 'a' + 1; j < k; j++) {
              if (used[j] == 0) {
                used[j] = 1;
                is[s[i] - 'a'] = j + 'a';
                fl = 1;
                break;
              }
            }
            if (fl) {
              break;
            }
            if (used[a[i] - 'a']) {
              can = 0;
              break;
            }
            used[a[i] - 'a'] = 1;
            is[s[i] - 'a'] = a[i];
            clearis.push_back(s[i] - 'a');
            clearus.push_back(a[i] - 'a');
          }
        }
        if (can == 0) {
          for (auto u : clearus) {
            used[u] = 0;
          }
          for (auto u : clearis) {
            is[u] = '0';
          }
        }
      }
      if (!can && !used[b[last] - 'a']) {
        used[b[last] - 'a'] = 1;
        is[s[last] - 'a'] = b[last];
        can = 1;
        for (long long i = last + 1; i < n; i++) {
          if (is[s[i] - 'a'] != '0') {
            if (is[s[i] - 'a'] > b[i]) {
              cout << "NO\n";
              return 0;
            } else if (is[s[i] - 'a'] < b[i]) {
              break;
            }
          } else {
            bool fl = 0;
            for (long long j = 0; j < b[i] - 'a'; j++) {
              if (used[j] == 0) {
                used[j] = 1;
                is[s[i] - 'a'] = j + 'a';
                fl = 1;
                break;
              }
            }
            if (fl) {
              break;
            }
            if (used[b[i] - 'a']) {
              cout << "NO\n";
              return 0;
            }
            used[b[i] - 'a'] = 1;
            is[s[i] - 'a'] = b[i];
          }
        }
      }
      if (!can) {
        cout << "NO\n";
        return 0;
      }
    }
  } else if (last != n && !morea) {
    for (long long i = last; i < n; i++) {
      if (is[s[i] - 'a'] != '0') {
        if (is[s[i] - 'a'] < a[i]) {
          cout << "NO\n";
          return 0;
        } else if (is[s[i] - 'a'] > a[i]) {
          break;
        }
      } else {
        bool fl = 0;
        for (long long j = a[i] - 'a' + 1; j < k; j++) {
          if (used[j] == 0) {
            used[j] = 1;
            is[s[i] - 'a'] = j + 'a';
            fl = 1;
            break;
          }
        }
        if (fl) {
          break;
        }
        if (used[a[i] - 'a']) {
          cout << "NO\n";
          return 0;
        }
        used[a[i] - 'a'] = 1;
        is[s[i] - 'a'] = a[i];
      }
    }
  } else if (last != n && !lessb) {
    for (long long i = last; i < n; i++) {
      if (is[s[i] - 'a'] != '0') {
        if (is[s[i] - 'a'] > b[i]) {
          cout << "NO\n";
          return 0;
        } else if (is[s[i] - 'a'] < b[i]) {
          break;
        }
      } else {
        bool fl = 0;
        for (long long j = 0; j < b[i] - 'a'; j++) {
          if (used[j] == 0) {
            used[j] = 1;
            is[s[i] - 'a'] = j + 'a';
            fl = 1;
            break;
          }
        }
        if (fl) {
          break;
        }
        if (used[b[i] - 'a']) {
          cout << "NO\n";
          return 0;
        }
        used[b[i] - 'a'] = 1;
        is[s[i] - 'a'] = b[i];
      }
    }
  }
  long long curr = 0;
  for (long long i = 0; i < k; i++) {
    if (is[i] == '0') {
      while (curr < k && used[curr]) {
        curr++;
      }
      is[i] = curr + 'a';
      used[curr] = 1;
    }
  }
  cout << "YES\n";
  for (auto u : is) {
    cout << u;
  }
  cout << "\n";
  return 0;
}
signed main() {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    main1();
  }
}
