#include <bits/stdc++.h>
using namespace std;
void doit(vector<int> &av, vector<int> &at) {
  int k = at.size();
  vector<int> x, y;
  for (int i = 0; i < k; i++) {
    if (av[i] < 0) x.push_back(i);
    if (at[i] < 0) y.push_back(i);
  }
  assert(x.size() == y.size());
  for (int i = 0; i < x.size(); ++i) {
    av[x[i]] = y[i];
    at[y[i]] = x[i];
  }
}
int boro(string s, string a, vector<int> at, vector<int> av) {
  int k = av.size();
  for (int i = 0; i < s.size(); ++i) {
    if (~av[s[i] - 'a']) {
      if (av[s[i] - 'a'] > a[i] - 'a') {
        break;
      }
      if (av[s[i] - 'a'] < a[i] - 'a') {
        return 0;
      }
    } else {
      int found = 0, x = 0;
      for (int j = k - 1; j >= a[i] - 'a'; j--)
        if (at[j] < 0) {
          av[s[i] - 'a'] = j;
          at[j] = s[i] - 'a';
          if (j > a[i] - 'a') x = 1;
          found = 1;
          break;
        }
      if (x) break;
      if (!found) return 0;
    }
  }
  doit(av, at);
  cout << "YES"
       << "\n";
  for (int i = 0; i < k; i++) cout << char(av[i] + 'a');
  cout << "\n";
  return 1;
}
int choto(string s, string a, vector<int> at, vector<int> av) {
  int k = av.size();
  for (int i = 0; i < s.size(); ++i) {
    if (~av[s[i] - 'a']) {
      if (av[s[i] - 'a'] > a[i] - 'a') {
        return 0;
      }
      if (av[s[i] - 'a'] < a[i] - 'a') {
        break;
      }
    } else {
      int found = 0, x = 0;
      for (int j = 0; j <= a[i] - 'a'; j++)
        if (at[j] < 0) {
          av[s[i] - 'a'] = j;
          at[j] = s[i] - 'a';
          if (j < a[i] - 'a') x = 1;
          found = 1;
          break;
        }
      if (x) break;
      if (!found) return 0;
    }
  }
  doit(av, at);
  cout << "YES"
       << "\n";
  for (int i = 0; i < k; i++) cout << char(av[i] + 'a');
  cout << "\n";
  return 1;
}
void solve() {
  int k;
  string s, a, b;
  cin >> k >> s >> a >> b;
  vector<int> av(k, -1), at(k, -1);
  int pos = -1;
  for (int i = 0; i < a.size(); ++i) {
    if (a[i] ^ b[i]) {
      pos = i;
      break;
    }
    if (av[s[i] - 'a'] < 0) {
      if (~at[a[i] - 'a']) {
        cout << "NO"
             << "\n";
        return;
      }
      av[s[i] - 'a'] = a[i] - 'a';
      at[a[i] - 'a'] = s[i] - 'a';
    }
    if (av[s[i] - 'a'] != a[i] - 'a') {
      cout << "NO"
           << "\n";
      return;
    }
  }
  if (pos < 0) {
    doit(av, at);
    cout << "YES"
         << "\n";
    for (int i = 0; i < k; i++) cout << char(av[i] + 'a');
    cout << "\n";
    return;
  }
  if (~av[s[pos] - 'a'] &&
      (av[s[pos] - 'a'] < a[pos] - 'a' || av[s[pos] - 'a'] > b[pos] - 'a')) {
    cout << "NO"
         << "\n";
    return;
  }
  if (~av[s[pos] - 'a'] &&
      (av[s[pos] - 'a'] > a[pos] - 'a' && av[s[pos] - 'a'] < b[pos] - 'a')) {
    doit(av, at);
    cout << "YES"
         << "\n";
    for (int i = 0; i < k; i++) cout << char(av[i] + 'a');
    cout << "\n";
    return;
  }
  if (av[s[pos] - 'a'] < 0)
    for (int i = a[pos] - 'a' + 1; i < b[pos] - 'a'; i++)
      if (at[i] < 0) {
        av[s[pos] - 'a'] = i;
        at[i] = s[pos] - 'a';
        doit(av, at);
        cout << "YES"
             << "\n";
        for (int i = 0; i < k; i++) cout << char(av[i] + 'a');
        cout << "\n";
        return;
      }
  if ((at[a[pos] - 'a'] < 0 && av[s[pos] - 'a'] < 0) ||
      at[a[pos] - 'a'] == s[pos] - 'a') {
    vector<int> av1 = av, at1 = at;
    at1[a[pos] - 'a'] = s[pos] - 'a';
    av1[s[pos] - 'a'] = a[pos] - 'a';
    if (boro(s, a, at1, av1)) return;
  }
  if ((at[b[pos] - 'a'] < 0 && av[s[pos] - 'a'] < 0) ||
      at[b[pos] - 'a'] == s[pos] - 'a') {
    vector<int> av1 = av, at1 = at;
    at1[b[pos] - 'a'] = s[pos] - 'a';
    av1[s[pos] - 'a'] = b[pos] - 'a';
    if (choto(s, b, at1, av1)) return;
  }
  cout << "NO"
       << "\n";
}
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int test, tc = 0;
  cin >> test;
  while (test--) {
    solve();
  }
}
