#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void ckmx(T &x, T &y) {
  x = max(x, y);
}
template <typename T>
inline void ckmi(T &x, T &y) {
  x = min(x, y);
}
template <typename T>
void read(T &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;
  x *= f;
}
char ss[1000010], ll[1000010], rr[1000010];
int s[1000010], l[1000010], r[1000010];
int ans[26], usd[26];
int k, n;
void ac() {
  puts("YES");
  int nw = 0;
  for (int i = 0; i < k; ++i) {
    if (ans[i] == -1) {
      while (usd[nw]) ++nw;
      ans[i] = nw;
      ++nw;
    }
    putchar(ans[i] + 'a');
  }
  puts("");
}
bool pdl(int fr) {
  for (int i = fr; i <= n; ++i) {
    if (ans[s[i]] != -1) {
      if (ans[s[i]] < l[i]) return 0;
      if (ans[s[i]] > l[i]) return 1;
    } else {
      for (int j = l[i] + 1; j < k; ++j)
        if (!usd[j]) {
          ans[s[i]] = j;
          usd[j] = 1;
          return 1;
        }
      if (!usd[l[i]])
        ans[s[i]] = l[i], usd[l[i]] = 1;
      else
        return 0;
    }
  }
  return 1;
}
bool pdr(int fr) {
  for (int i = fr; i <= n; ++i) {
    if (ans[s[i]] != -1) {
      if (ans[s[i]] > r[i]) return 0;
      if (ans[s[i]] < r[i]) return 1;
    } else {
      for (int j = r[i] - 1; j >= 0; --j)
        if (!usd[j]) {
          ans[s[i]] = j;
          usd[j] = 1;
          return 1;
        }
      if (!usd[r[i]])
        ans[s[i]] = r[i], usd[r[i]] = 1;
      else
        return 0;
    }
  }
  return 1;
}
int main() {
  int t;
  read(t);
  while (t--) {
    memset(ans, -1, sizeof(ans));
    memset(usd, 0, sizeof(usd));
    read(k);
    scanf("%s", ss + 1);
    scanf("%s", ll + 1);
    scanf("%s", rr + 1);
    n = strlen(ss + 1);
    int f = 0;
    for (int i = 1; i <= n; ++i)
      s[i] = ss[i] - 'a', l[i] = ll[i] - 'a', r[i] = rr[i] - 'a';
    for (int i = 1; i <= n; ++i) {
      if (ans[s[i]] != -1) {
        int nw = ans[s[i]];
        if (nw > l[i] && nw < r[i])
          break;
        else if (nw < l[i] || nw > r[i]) {
          f = 1;
          break;
        } else if (l[i] == r[i])
          continue;
        else if (nw == l[i]) {
          f = 1 - pdl(i + 1);
          break;
        } else {
          f = 1 - pdr(i + 1);
          break;
        }
      } else {
        int ff = 0;
        for (int j = l[i] + 1; j <= r[i] - 1; ++j)
          if (!usd[j]) {
            ans[s[i]] = j;
            usd[j] = 1;
            ff = 1;
            break;
          }
        if (ff) break;
        if (l[i] == r[i]) {
          if (!usd[l[i]])
            ans[s[i]] = l[i], usd[l[i]] = 1;
          else {
            f = 1;
            break;
          }
        } else {
          int sv1[26], sv2[26];
          for (int j = 0; j < k; ++j) sv1[j] = ans[j], sv2[j] = usd[j];
          if (!usd[l[i]]) {
            ans[s[i]] = l[i], usd[l[i]] = 1;
            if (pdl(i + 1)) break;
            for (int j = 0; j < k; ++j) ans[j] = sv1[j], usd[j] = sv2[j];
          }
          if (!usd[r[i]]) {
            ans[s[i]] = r[i], usd[r[i]] = 1;
            if (pdr(i + 1)) break;
          }
          f = 1;
          break;
        }
      }
    }
    if (f == 1)
      puts("NO");
    else
      ac();
  }
  return 0;
}
