#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
template <typename T>
void pcopy(T* pst, const T* ped, T* pval) {
  for (; pst != ped; *(pst++) = *(pval++))
    ;
}
int cti(char x) { return x - 'a'; }
int Case, K, n;
char T[30];
bool used[30];
char s[N], ss[N], a[N], b[N];
bool dfs(int d, int N, bool onL, bool onR) {
  if (d > N) {
    int c = 0;
    puts("YES");
    for (int i = 0; i < K; i++) {
      if (!T[i]) {
        while (used[c]) c++;
        used[c] = true;
        T[i] = c + 'a';
      }
      putchar(T[i]);
    }
    putchar('\n');
    return true;
  }
  char L = ((onL) ? (a[d]) : ('a'));
  char R = ((onR) ? (b[d]) : ('a' + K - 1));
  char& x = T[cti(s[d])];
  if (!x) {
    for (int _i = L, i; _i <= R; _i++) {
      i = _i - 'a';
      if (!used[i]) {
        used[i] = true;
        x = _i;
        if (dfs(d + 1, N, onL && _i == L, onR && _i == R)) {
          return true;
        }
        used[i] = false;
        x = 0;
      }
    }
    return false;
  }
  if (x < L) return false;
  if (x > R) return false;
  return dfs(d + 1, N, onL && x == L, onR && x == R);
}
inline void solve() {
  scanf("%d", &K);
  scanf("%s", s + 1);
  scanf("%s", a + 1);
  scanf("%s", b + 1);
  n = strlen(s + 1);
  memset(T, 0, sizeof(T));
  memset(used, false, sizeof(used));
  if (!dfs(1, n, true, true)) {
    puts("NO");
  }
}
int main() {
  scanf("%d", &Case);
  while (Case--) {
    solve();
  }
  return 0;
}
