#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
const int MOD = 998244353;
int TC;
int N, K;
string S, A, B;
int C[26];
bool cant[26];
int op = 0;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> TC;
  while (TC--) {
    memset(C, -1, sizeof C);
    memset(cant, 0, sizeof cant);
    op = 0;
    cin >> K >> S >> A >> B;
    N = S.length();
    bool poss = true;
    for (int i = (0); i <= (N - 1); i++) {
      if (op == 0) {
        if (C[S[i] - 'a'] != -1) {
          char c = C[S[i] - 'a'] + 'a';
          if (A[i] < c && c < B[i])
            break;
          else if (c < A[i] || B[i] < c) {
            poss = false;
            break;
          } else if (A[i] == c && B[i] == c)
            continue;
          else if (A[i] == c) {
            op = 1;
            continue;
          } else if (B[i] == c) {
            op = 2;
            continue;
          }
        } else {
          if (A[i] > B[i]) {
            poss = false;
            break;
          } else if (A[i] == B[i]) {
            C[S[i] - 'a'] = A[i] - 'a';
            if (cant[A[i] - 'a']) {
              poss = false;
              break;
            }
            cant[A[i] - 'a'] = true;
          } else {
            for (int j = (A[i] - 'a' + 1); j <= (B[i] - 'a' - 1); j++) {
              if (cant[j]) continue;
              C[S[i] - 'a'] = j;
              cant[j] = true;
              break;
            }
            if (C[S[i] - 'a'] != -1) break;
            C[S[i] - 'a'] = A[i] - 'a';
            if (cant[A[i] - 'a']) {
              poss = false;
              break;
            }
            cant[A[i] - 'a'] = true;
            op = 1;
          }
        }
      } else if (op == 1) {
        if (C[S[i] - 'a'] != -1) {
          char c = C[S[i] - 'a'] + 'a';
          if (A[i] < c)
            break;
          else if (A[i] <= c)
            continue;
          else {
            poss = false;
            break;
          }
        } else {
          for (int j = (A[i] - 'a' + 1); j <= (K - 1); j++) {
            if (cant[j]) continue;
            C[S[i] - 'a'] = j;
            cant[j] = true;
            break;
          }
          if (C[S[i] - 'a'] != -1) break;
          C[S[i] - 'a'] = A[i] - 'a';
          if (cant[A[i] - 'a']) {
            poss = false;
            break;
          }
          cant[A[i] - 'a'] = true;
        }
      } else if (op == 2) {
        if (C[S[i] - 'a'] != -1) {
          char c = C[S[i] - 'a'] + 'a';
          if (c < B[i])
            break;
          else if (c == B[i])
            continue;
          else {
            poss = false;
            break;
          }
        } else {
          for (int j = (0); j <= (B[i] - 'a' - 1); j++) {
            if (cant[j]) continue;
            C[S[i] - 'a'] = j;
            cant[j] = true;
            break;
          }
          if (C[S[i] - 'a'] != -1) break;
          C[S[i] - 'a'] = B[i] - 'a';
          if (cant[B[i] - 'a']) {
            poss = false;
            break;
          }
          cant[B[i] - 'a'] = true;
        }
      }
    }
    if (poss) {
      cout << "YES\n";
      char c = 'a';
      for (int i = (0); i <= (K - 1); i++) {
        while (c - 'a' < K && cant[c - 'a']) c++;
        if (C[i] == -1)
          cout << c++;
        else
          cout << (char)(C[i] + 'a');
      }
      cout << "\n";
      continue;
    }
    memset(C, -1, sizeof C);
    memset(cant, 0, sizeof cant);
    op = 0;
    poss = true;
    for (int i = (0); i <= (N - 1); i++) {
      if (op == 0) {
        if (C[S[i] - 'a'] != -1) {
          char c = C[S[i] - 'a'] + 'a';
          if (A[i] < c && c < B[i])
            break;
          else if (c < A[i] || B[i] < c) {
            poss = false;
            break;
          } else if (A[i] == c && B[i] == c)
            continue;
          else if (A[i] == c) {
            op = 1;
            continue;
          } else if (B[i] == c) {
            op = 2;
            continue;
          }
        } else {
          if (A[i] > B[i]) {
            poss = false;
            break;
          } else if (A[i] == B[i]) {
            C[S[i] - 'a'] = A[i] - 'a';
            if (cant[A[i] - 'a']) {
              poss = false;
              break;
            }
            cant[A[i] - 'a'] = true;
          } else {
            for (int j = (A[i] - 'a' + 1); j <= (B[i] - 'a' - 1); j++) {
              if (cant[j]) continue;
              C[S[i] - 'a'] = j;
              cant[j] = true;
              break;
            }
            if (C[S[i] - 'a'] != -1) break;
            C[S[i] - 'a'] = B[i] - 'a';
            if (cant[B[i] - 'a']) {
              poss = false;
              break;
            }
            cant[B[i] - 'a'] = true;
            op = 2;
          }
        }
      } else if (op == 1) {
        if (C[S[i] - 'a'] != -1) {
          char c = C[S[i] - 'a'] + 'a';
          if (A[i] < c)
            break;
          else if (A[i] <= c)
            continue;
          else {
            poss = false;
            break;
          }
        } else {
          for (int j = (A[i] - 'a' + 1); j <= (K - 1); j++) {
            if (cant[j]) continue;
            C[S[i] - 'a'] = j;
            cant[j] = true;
            break;
          }
          if (C[S[i] - 'a'] != -1) break;
          C[S[i] - 'a'] = A[i] - 'a';
          if (cant[A[i] - 'a']) {
            poss = false;
            break;
          }
          cant[A[i] - 'a'] = true;
        }
      } else if (op == 2) {
        if (C[S[i] - 'a'] != -1) {
          char c = C[S[i] - 'a'] + 'a';
          if (c < B[i])
            break;
          else if (c == B[i])
            continue;
          else {
            poss = false;
            break;
          }
        } else {
          for (int j = (0); j <= (B[i] - 'a' - 1); j++) {
            if (cant[j]) continue;
            C[S[i] - 'a'] = j;
            cant[j] = true;
            break;
          }
          if (C[S[i] - 'a'] != -1) break;
          C[S[i] - 'a'] = B[i] - 'a';
          if (cant[B[i] - 'a']) {
            poss = false;
            break;
          }
          cant[B[i] - 'a'] = true;
        }
      }
    }
    if (poss) {
      cout << "YES\n";
      char c = 'a';
      for (int i = (0); i <= (K - 1); i++) {
        while (c - 'a' < K && cant[c - 'a']) c++;
        if (C[i] == -1)
          cout << c++;
        else
          cout << (char)(C[i] + 'a');
      }
      cout << "\n";
      continue;
    }
    cout << "NO\n";
  }
}
