#include <bits/stdc++.h>
template <class t>
inline void read(t &s) {
  s = 0;
  register int f = 1;
  register char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
  s *= f;
  return;
}
template <class t, class... A>
inline void read(t &x, A &...a) {
  read(x);
  read(a...);
}
template <class t>
inline void write(t x) {
  if (x < 0) putchar('-'), x = -x;
  int buf[21], top = 0;
  while (x) buf[++top] = x % 10, x /= 10;
  if (!top) buf[++top] = 0;
  while (top) putchar(buf[top--] ^ '0');
  return;
}
inline void setIn(std::string s) {
  freopen(s.c_str(), "r", stdin);
  return;
}
inline void setOut(std::string s) {
  freopen(s.c_str(), "w", stdout);
  return;
}
inline void setIO(std::string s = "") {
  setIn(s + ".in");
  setOut(s + ".out");
  return;
}
template <class t>
inline bool checkmin(t &x, t y) {
  if (x > y) {
    x = y;
    return 1;
  }
  return 0;
}
template <class t>
inline bool checkmax(t &x, t y) {
  if (x < y) {
    x = y;
    return 1;
  }
  return 0;
}
inline int lowbit(int x) { return x & (-x); }
const int MaxN = 1e6 + 50;
int cur[26], used[26], tmp1[26], tmp2[26];
char s[MaxN], a[MaxN], b[MaxN];
int n, K, flg;
inline void goL(int st) {
  std::memcpy(tmp1, used, sizeof(used)), std::memcpy(tmp2, cur, sizeof(cur));
  register int fail = 0;
  for (int i = st; i <= n; ++i)
    if (~cur[s[i] - 'a']) {
      register int x = cur[s[i] - 'a'] + 'a';
      if (x < a[i]) {
        fail = 1;
        break;
      }
      if (x > a[i]) {
        flg = 1;
        return;
      }
    } else {
      for (int j = a[i] - 'a' + 1; j < K; ++j)
        if (!used[j]) return used[j] = 1, cur[s[i] - 'a'] = j, flg = 1, void();
      if (used[a[i] - 'a']) {
        fail = 1;
        break;
      }
      used[a[i] - 'a'] = 1, cur[s[i] - 'a'] = a[i] - 'a';
    }
  if (!fail) return flg = 1, void();
  std::memcpy(used, tmp1, sizeof(used)), std::memcpy(cur, tmp2, sizeof(cur));
}
inline void goR(int st) {
  std::memcpy(tmp1, used, sizeof(used)), std::memcpy(tmp2, cur, sizeof(cur));
  register int fail = 0;
  for (int i = st; i <= n; ++i)
    if (~cur[s[i] - 'a']) {
      register int x = cur[s[i] - 'a'] + 'a';
      if (x > b[i]) {
        fail = 1;
        break;
      }
      if (x < b[i]) {
        flg = 1;
        return;
      }
    } else {
      for (int j = 0; j < b[i] - 'a'; ++j)
        if (!used[j]) return used[j] = 1, cur[s[i] - 'a'] = j, flg = 1, void();
      if (used[b[i] - 'a']) {
        fail = 1;
        break;
      }
      used[b[i] - 'a'] = 1, cur[s[i] - 'a'] = b[i] - 'a';
    }
  if (!fail) return flg = 1, void();
  std::memcpy(used, tmp1, sizeof(used)), std::memcpy(cur, tmp2, sizeof(cur));
}
inline void work() {
  read(K), std::scanf("%s%s%s", s + 1, a + 1, b + 1), n = std::strlen(s + 1),
                                                      flg = 0;
  std::memset(cur, -1, K * sizeof(int));
  std::memset(used, 0, K * sizeof(int));
  for (int i = 1; i <= n; ++i) {
    if (~cur[s[i] - 'a']) {
      register int x = cur[s[i] - 'a'] + 'a';
      if (x < a[i] || x > b[i]) break;
      if (x > a[i] && x < b[i]) {
        flg = 1;
        break;
      }
      if (a[i] != b[i]) {
        if (x == a[i]) goL(i + 1);
        if (flg) break;
        if (x == b[i]) goR(i + 1);
        if (flg) break;
        break;
      }
    } else {
      for (int j = a[i] - 'a' + 1; j < b[i] - 'a'; ++j)
        if (!used[j]) {
          used[j] = 1, cur[s[i] - 'a'] = j;
          flg = 1;
          break;
        }
      if (flg) break;
      if (a[i] == b[i]) {
        if (used[a[i] - 'a']) break;
        used[a[i] - 'a'] = 1, cur[s[i] - 'a'] = a[i] - 'a';
      } else {
        if (!used[a[i] - 'a']) {
          used[a[i] - 'a'] = 1, cur[s[i] - 'a'] = a[i] - 'a';
          goL(i + 1);
          if (flg) break;
          used[a[i] - 'a'] = 0, cur[s[i] - 'a'] = -1;
        }
        if (!used[b[i] - 'a']) {
          used[b[i] - 'a'] = 1, cur[s[i] - 'a'] = b[i] - 'a';
          goR(i + 1);
          if (flg) break;
          used[b[i] - 'a'] = 0, cur[s[i] - 'a'] = -1;
        }
        break;
      }
    }
    if (i == n) {
      flg = 1;
      break;
    }
  }
  if (!flg) return std::puts("NO"), void();
  std::puts("YES");
  for (int i = 0; i < K; ++i)
    for (int j = 0; (!~cur[i]) && j < K; ++j)
      if (!used[j]) cur[i] = j, used[j] = 1;
  for (int i = 0; i < K; ++i) std::putchar(cur[i] + 'a');
  std::puts("");
}
signed main(void) {
  int t;
  read(t);
  while (t--) work();
  return 0;
}
