#include <bits/stdc++.h>
using namespace std;
int T, n, f, a[1000005], b[1000005], s[1000005], atos[30], stoa[30], l, k, z;
string stra, strb, str;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> T;
  for (int ca = 1; ca <= T; ca++) {
    cin >> k >> str >> stra >> strb;
    n = str.size();
    for (int i = 0; i < n; i++) {
      a[i] = stra[i] - 'a';
      b[i] = strb[i] - 'a';
      s[i] = str[i] - 'a';
    }
    memset(atos, -1, sizeof atos);
    memset(stoa, -1, sizeof stoa);
    l = -1;
    f = 0;
    z = k - 1;
    for (int i = 0; i < n; i++) {
      if (stoa[s[i]] != -1) {
        if (stoa[s[i]] > a[i])
          l = -3;
        else if (l != -3 && stoa[s[i]] < a[i]) {
          f = 1;
          break;
        }
        continue;
      }
      for (int j = (l == -3 ? 0 : a[i]); j < k; j++) {
        if (atos[j] == -1) {
          stoa[s[i]] = j;
          atos[j] = s[i];
          if (j == a[i] && l != -3) {
            if (j != z)
              l = i;
            else {
              for (int aa = k - 1; aa >= 0; aa--) {
                if (atos[aa] == -1) {
                  z = aa;
                  break;
                }
              }
            }
          } else
            l = -3;
          break;
        }
        if (j == k - 1 && l != -3) {
          f = 1;
          goto P;
        }
      }
    }
  P:
    if (f == 1) {
      if (l == -1) {
        cout << "NO" << endl;
        goto PP;
      }
      memset(atos, -1, sizeof atos);
      memset(stoa, -1, sizeof stoa);
      for (int i = 0; i < l; i++) {
        stoa[s[i]] = a[i];
        atos[a[i]] = s[i];
      }
      for (int j = a[l] + 1; j < k; j++) {
        if (atos[j] == -1) {
          stoa[s[l]] = j;
          atos[j] = s[l];
          break;
        }
      }
      for (int i = l + 1; i < n; i++) {
        if (stoa[s[i]] != -1) continue;
        for (int j = 0; j < k; j++) {
          if (atos[j] == -1) {
            stoa[s[i]] = j;
            atos[j] = s[i];
            break;
          }
        }
      }
    }
    f = 0;
    for (int i = 0; i < n; i++) {
      if (stoa[s[i]] < b[i]) break;
      if (stoa[s[i]] > b[i]) f = 1;
    }
    for (int i = 0; i < k; i++) {
      if (stoa[i] == -1) {
        for (int j = 0; j < k; j++) {
          if (atos[j] == -1) {
            stoa[i] = j;
            atos[j] = i;
            break;
          }
        }
      }
    }
    if (f == 0) {
      cout << "YES\n";
      for (int i = 0; i < k; i++) cout << (char)(stoa[i] + 'a');
      cout << "\n";
    } else
      cout << "NO\n";
  PP:
    continue;
  }
  return 0;
}
