#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int t, k, n, up;
int cg[30];
bool used[30];
char s[maxn], a[maxn], b[maxn];
inline bool dfs(int pos, bool lil, bool lir) {
  if (pos >= n) return true;
  char c = s[pos], l = a[pos], r = b[pos];
  int now = c - 'a';
  int mic = lil ? l - 'a' : 0;
  int mac = lir ? r - 'a' : up;
  if (cg[now] == -1) {
    for (register int i = mic; i <= mac; ++i)
      if (!used[i]) {
        used[i] = 1;
        int pre = cg[now];
        cg[now] = i;
        if (dfs(pos + 1, lil & (i == mic), lir & (i == mac))) return true;
        cg[now] = pre;
        used[i] = 0;
      }
    return false;
  } else if (cg[now] < mic || cg[now] > mac)
    return false;
  else
    return dfs(pos + 1, lil & (cg[now] == mic), lir & (cg[now] == mac));
}
inline void solve() {
  memset(used, 0, sizeof(used));
  memset(cg, -1, sizeof(cg));
  scanf("%d", &k);
  up = k - 1;
  scanf("%s%s%s", s, a, b);
  n = strlen(s);
  for (register int i = 0; i < n; ++i)
    if ((s[i] - 'a') > up) {
      printf("NO\n");
      return;
    }
  if (dfs(0, 1, 1)) {
    printf("YES\n");
    for (register int i = 0; i < k; ++i)
      if (cg[i] == -1)
        for (register int j = 0; j < k; ++j)
          if (!used[j]) {
            used[j] = 1;
            cg[i] = j;
            break;
          }
    for (register int i = 0; i < k; ++i) printf("%c", cg[i] + 'a');
    printf("\n");
    return;
  }
  printf("NO\n");
  return;
}
int main() {
  scanf("%d", &t);
  while (t--) solve();
  return 0;
}
