#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, T b) {
  return b < a ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, T b) {
  return b > a ? a = b, 1 : 0;
}
inline int read() {
  int x(0), sgn(1);
  char ch(getchar());
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') sgn = -1;
  for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
  return x * sgn;
}
void File() {}
const int N = 1e6 + 1e3;
char A[N], B[N], S[N];
int k, n;
bool App[26];
int ans[26];
bool Solve(int dep, bool L, bool R) {
  if (L && R || dep > n) return true;
  int down = A[dep] - 'a', up = B[dep] - 'a', id = S[dep] - 'a';
  if (~ans[id]) {
    if (!L && ans[id] < down || !R && ans[id] > up) return false;
    return Solve(dep + 1, L || ans[id] > down, R || ans[id] < up);
  } else {
    for (register int ch = (L ? 0 : down), chend = (int)(R ? k - 1 : up);
         ch <= chend; ++ch)
      if (!App[ch]) {
        App[ans[id] = ch] = true;
        if (Solve(dep + 1, L || ans[id] > down, R || ans[id] < up)) return true;
        ans[id] = -1, App[ch] = false;
      }
    return false;
  }
}
int main() {
  File();
  int cases = read();
  while (cases--) {
    k = read();
    scanf("%s", S + 1);
    scanf("%s", A + 1);
    scanf("%s", B + 1);
    n = strlen(S + 1);
    memset(App, false, sizeof(App));
    memset(ans, -1, sizeof(ans));
    if (Solve(1, false, false)) {
      puts("YES");
      for (register int i = (0), iend = (int)(k); i < iend; ++i) {
        if (!~ans[i])
          for (register int j = (0), jend = (int)(k); j < jend; ++j)
            if (!App[j]) {
              App[ans[i] = j] = true;
              break;
            }
        putchar(ans[i] + 'a');
      }
      putchar('\n');
    } else
      puts("NO");
  }
  return 0;
}
