#include <bits/stdc++.h>
using namespace std;
int T, k, l;
char s_[1234567], a_[1234567], b_[1234567], ys[129], fy[129], yt[129], ft[129],
    *a = a_, *b = b_, *s = s_;
bool can_go(char a, char b) {
  if (ys[a] != -1 && ys[a] != b) return 0;
  if (fy[b] != -1 && fy[b] != a) return 0;
  return 1;
}
void sett(char a, char b) {
  ys[a] = b;
  fy[b] = a;
}
void fix_empty_and_op() {
  static int as[233];
  int an = 0;
  for (int i = 0; i < k; ++i)
    if (fy[i + 'a'] == -1) as[an++] = i + 'a';
  an = 0;
  for (int i = 0; i < k; ++i)
    if (ys[i + 'a'] == -1) ys[i + 'a'] = as[an++];
  puts("YES");
  for (int i = 0; i < k; ++i) putchar(ys[i + 'a']);
  puts("");
  return;
}
void sol() {
  a = a_, b = b_, s = s_;
  scanf("%d%s%s%s", &k, s, a, b);
  for (int i = 0; i < k; ++i) ys[i + 'a'] = fy[i + 'a'] = -1;
  l = strlen(a);
  while (l && a[0] == b[0]) {
    if (!can_go(s[0], a[0])) {
      puts("NO");
      return;
    }
    sett(s[0], a[0]);
    ++a;
    ++b;
    ++s;
    --l;
  }
  if (!l) {
    fix_empty_and_op();
    return;
  }
  for (int x = a[0] + 1; x < b[0]; ++x)
    if (can_go(s[0], x)) {
      sett(s[0], x);
      fix_empty_and_op();
      return;
    }
  for (int i = 0; i < k; ++i)
    yt[i + 'a'] = ys[i + 'a'], ft[i + 'a'] = fy[i + 'a'];
  if (can_go(s[0], a[0])) {
    sett(s[0], a[0]);
    for (int t = 1; t < l; ++t) {
      for (int x = a[t] + 1; x < k + 'a'; ++x) {
        if (can_go(s[t], x)) {
          sett(s[t], x);
          fix_empty_and_op();
          return;
        }
      }
      if (!can_go(s[t], a[t])) goto next_shit;
      sett(s[t], a[t]);
    }
    fix_empty_and_op();
    return;
  }
next_shit:
  for (int i = 0; i < k; ++i)
    ys[i + 'a'] = yt[i + 'a'], fy[i + 'a'] = ft[i + 'a'];
  if (can_go(s[0], b[0])) {
    sett(s[0], b[0]);
    for (int t = 1; t < l; ++t) {
      for (int x = b[t] - 1; x >= 'a'; --x) {
        if (can_go(s[t], x)) {
          sett(s[t], x);
          fix_empty_and_op();
          return;
        }
      }
      if (!can_go(s[t], b[t])) {
        puts("NO");
        return;
      }
      sett(s[t], b[t]);
    }
    fix_empty_and_op();
    return;
  }
  {
    puts("NO");
    return;
  }
}
int main() {
  scanf("%d", &T);
  while (T--) sol();
}
