#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
int T, K, mp[26], mp2[26];
char s[maxn], A[maxn], B[maxn];
bool used[26], used2[26];
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &K);
    scanf("%s %s %s", s + 1, A + 1, B + 1);
    int n = strlen(s + 1);
    auto solve = [&]() {
      memcpy(mp2, mp, sizeof(mp2));
      memcpy(used2, used, sizeof(used2));
      int lst = K - 1;
      for (int i = 1; i <= n; i++)
        if (!~mp2[s[i] - 'a']) {
          while (used2[lst]) lst--;
          mp2[s[i] - 'a'] = lst, used2[lst] = 1;
        }
      bool flag = 1;
      for (int i = 1; i <= n; i++) {
        if ((mp2[s[i] - 'a'] + 'a') ^ A[i]) {
          flag = (mp2[s[i] - 'a'] + 'a') > A[i];
          break;
        }
      }
      return flag;
    };
    memset(mp, -1, sizeof(mp));
    memset(used, 0, sizeof(used));
    if (!solve()) {
      printf("NO\n");
      continue;
    }
    bool cur = 0;
    for (int i = 1; i <= n; i++) {
      if (!~mp[s[i] - 'a']) {
        bool chk = 0;
        for (int j = !cur ? (A[i] - 'a') : 0; j < K; j++)
          if (!used[j]) {
            mp[s[i] - 'a'] = j, used[j] = 1;
            if (!solve())
              used[j] = 0;
            else {
              chk = 1, cur |= (j > A[i] - 'a');
              break;
            }
          }
        assert(chk);
      } else {
        cur |= ((mp[s[i] - 'a'] + 'a') > A[i]);
      }
    }
    bool flag = 1;
    for (int i = 1; i <= n; i++) {
      if ((mp[s[i] - 'a'] + 'a') ^ B[i]) {
        flag = (mp[s[i] - 'a'] + 'a') < B[i];
        break;
      }
    }
    if (!flag) {
      printf("NO\n");
      continue;
    }
    printf("YES\n");
    int lst = K - 1;
    for (int i = 0; i < K; i++) {
      if (!~mp[i]) {
        while (used[lst]) lst--;
        mp[i] = lst, used[lst] = 1;
      }
      putchar(mp[i] + 'a');
    }
    printf("\n");
  }
  return 0;
}
