#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
bool Finish_read;
template <class T>
inline void read(T &x) {
  Finish_read = 0;
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    if (ch == EOF) return;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  x *= f;
  Finish_read = 1;
}
template <class T>
inline void print(T x) {
  if (x / 10 != 0) print(x / 10);
  putchar(x % 10 + '0');
}
template <class T>
inline void writeln(T x) {
  if (x < 0) putchar('-');
  x = abs(x);
  print(x);
  putchar('\n');
}
template <class T>
inline void write(T x) {
  if (x < 0) putchar('-');
  x = abs(x);
  print(x);
}
const int maxn = 1000006;
int T, n, k, used[26], td[26];
char a[maxn], b[maxn], s[maxn];
unordered_map<char, char> ins, tmp;
inline int solveb(int pos) {
  for (int i = pos; i <= n; ++i) {
    if (!ins[s[i]]) {
      for (int j = 0; j < b[i] - 'a'; ++j)
        if (!used[j]) {
          ins[s[i]] = j + 'a', used[j] = 1;
          return 1;
        }
      if (!used[b[i] - 'a']) {
        ins[s[i]] = b[i], used[b[i] - 'a'] = 1;
        continue;
      }
      return 0;
    } else {
      if (ins[s[i]] > b[i])
        return 0;
      else if (ins[s[i]] < b[i])
        return 1;
    }
  }
  return 1;
}
inline int solvea(int pos) {
  for (int i = pos; i <= n; ++i) {
    if (!ins[s[i]]) {
      for (int j = a[i] - 'a' + 1; j < k; ++j)
        if (!used[j]) {
          ins[s[i]] = j + 'a', used[j] = 1;
          return 1;
        }
      if (!used[a[i] - 'a']) {
        ins[s[i]] = a[i], used[a[i] - 'a'] = 1;
        continue;
      }
      return 0;
    } else {
      if (ins[s[i]] < a[i])
        return 0;
      else if (ins[s[i]] > a[i])
        return 1;
    }
  }
  return 1;
}
inline void output() {
  int pos = 0;
  for (int i = 0; i < k; ++i) {
    if (ins[i + 'a'])
      putchar(ins[i + 'a']);
    else {
      while (pos < k && used[pos]) ++pos;
      used[pos] = 1, putchar(pos + 'a');
    }
  }
  puts("");
}
inline void solve() {
  for (int i = 1; i <= n; ++i) {
    if (a[i] > b[i]) {
      puts("NO");
      return;
    } else if (a[i] == b[i]) {
      if (!ins[s[i]]) {
        if (used[a[i] - 'a']) {
          puts("NO");
          return;
        }
        ins[s[i]] = a[i], used[a[i] - 'a'] = 1;
      } else {
        if (ins[s[i]] != a[i]) {
          puts("NO");
          return;
        }
      }
    } else {
      if (ins[s[i]]) {
        if (ins[s[i]] < a[i] || ins[s[i]] > b[i]) {
          puts("NO");
          return;
        }
        if (ins[s[i]] == a[i]) {
          int tmp = solvea(i + 1);
          if (tmp) {
            puts("YES");
            output();
            return;
          } else {
            puts("NO");
            return;
          }
        }
        if (ins[s[i]] == b[i]) {
          int tmp = solveb(i + 1);
          if (tmp) {
            puts("YES");
            output();
            return;
          } else {
            puts("NO");
            return;
          }
        }
        puts("YES");
        output();
        return;
      }
      for (int j = a[i] - 'a' + 1; j < b[i] - 'a'; ++j)
        if (!used[j]) {
          used[j] = 1, ins[s[i]] = j + 'a';
          puts("YES");
          output();
          return;
        }
      tmp = ins, memcpy(td, used, sizeof used);
      if (!used[a[i] - 'a']) {
        ins[s[i]] = a[i], used[a[i] - 'a'] = 1;
        int tmp = solvea(i + 1);
        if (tmp) {
          puts("YES");
          output();
          return;
        }
      }
      ins = tmp, memcpy(used, td, sizeof td);
      if (!used[b[i] - 'a']) {
        ins[s[i]] = b[i], used[b[i] - 'a'] = 1;
        int tmp = solveb(i + 1);
        if (tmp) {
          puts("YES");
          output();
          return;
        }
      }
      puts("NO");
      return;
    }
  }
  puts("YES");
  output();
  return;
}
int main() {
  for (read(T); T--;)
    read(k), ins.clear(), memset(used, 0, sizeof used),
        scanf("%s%s%s", s + 1, a + 1, b + 1), n = strlen(a + 1), solve();
}
