#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-5;
const long double PI = acos(-1);
const int INF = (int)1e9;
const long long INFF = (long long)1e18;
const int mod = (int)1e9 + 7;
const int MXN = (int)1e6 + 7;
char s[MXN], s1[MXN], s2[MXN];
int sub[27], used[27];
int k, l;
bool sp1(int st) {
  int tsub[27], tused[27];
  for (int i = 0; i < k; ++i) {
    tsub[i] = sub[i];
    tused[i] = used[i];
  }
  if (tused[s1[st] - 'a']) return 0;
  tsub[s[st] - 'a'] = s1[st] - 'a';
  tused[s1[st] - 'a'] = 1;
  for (int i = st + 1; i < l + 1; ++i) {
    int ch = s[i] - 'a';
    if (tsub[ch] != -1) {
      ch = tsub[ch];
      if (!(s1[i] - 'a' <= ch)) return 0;
      if (s1[i] - 'a' == ch)
        continue;
      else
        break;
    }
    int ll = s1[i] - 'a';
    bool ok = 0;
    for (int j = ll + 1; j < k; ++j) {
      if (!tused[j]) {
        tsub[ch] = j;
        tused[j] = 1;
        ok = 1;
        break;
      }
    }
    if (ok) break;
    if (tused[ll]) return 0;
    tsub[ch] = ll;
    tused[ll] = 1;
  }
  for (int i = 0; i < k; ++i) {
    used[i] = tused[i];
    sub[i] = tsub[i];
  }
  int cur = 0;
  for (int i = 0; i < k; ++i) {
    if (sub[i] == -1) {
      while (used[cur]) cur++;
      sub[i] = cur;
      used[cur] = 1;
    }
  }
  return 1;
}
bool sp2(int st) {
  int tsub[27], tused[27];
  for (int i = 0; i < k; ++i) {
    tsub[i] = sub[i];
    tused[i] = used[i];
  }
  if (tused[s2[st] - 'a']) return 0;
  tsub[s[st] - 'a'] = s2[st] - 'a';
  tused[s2[st] - 'a'] = 1;
  for (int i = st + 1; i < l + 1; ++i) {
    int ch = s[i] - 'a';
    if (tsub[ch] != -1) {
      ch = tsub[ch];
      if (!(ch <= s2[i] - 'a')) return 0;
      if (ch == s2[i] - 'a')
        continue;
      else
        break;
    }
    int ll = s2[i] - 'a';
    bool ok = 0;
    for (int j = 0; j < ll; ++j) {
      if (!tused[j]) {
        tsub[ch] = j;
        tused[j] = 1;
        ok = 1;
        break;
      }
    }
    if (ok) break;
    if (tused[ll]) return 0;
    tsub[ch] = ll;
    tused[ll] = 1;
  }
  for (int i = 0; i < k; ++i) {
    used[i] = tused[i];
    sub[i] = tsub[i];
  }
  int cur = 0;
  for (int i = 0; i < k; ++i) {
    if (sub[i] == -1) {
      while (used[cur]) cur++;
      sub[i] = cur;
      used[cur] = 1;
    }
  }
  return 1;
}
char ans[28];
int main(void) {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &k);
    for (int i = 0; i < k; ++i) sub[i] = -1;
    for (int i = 0; i < k; ++i) used[i] = 0;
    scanf("%s %s %s", s + 1, s1 + 1, s2 + 1);
    l = strlen(s + 1);
    bool gg = 0;
    for (int i = 1; i < l + 1; ++i) {
      int ch = s[i] - 'a';
      if (sub[ch] != -1) {
        ch = sub[ch];
        if (!(s1[i] - 'a' <= ch && ch <= s2[i] - 'a')) {
          gg = 1;
          break;
        } else {
          if (s1[i] == s2[i]) continue;
          if (s1[i] - 'a' < ch && ch < s2[i] - 'a')
            break;
          else if (s1[i] - 'a' == ch) {
            used[ch] = 0;
            sub[s[i] - 'a'] = -1;
            if (sp1(i)) break;
            gg = 1;
            break;
          } else {
            used[ch] = 0;
            sub[s[i] - 'a'] = -1;
            if (sp2(i)) break;
            gg = 1;
            break;
          }
        }
      }
      if (s1[i] != s2[i]) {
        int ll = s1[i] - 'a';
        int rr = s2[i] - 'a';
        bool ok = 0;
        for (int j = ll + 1; j < rr; ++j) {
          if (!used[j]) {
            sub[ch] = j;
            used[j] = 1;
            ok = 1;
            break;
          }
        }
        if (ok) break;
        if (sp1(i)) break;
        if (sp2(i)) break;
        gg = 1;
        break;
      } else {
        if (used[s1[i] - 'a']) {
          gg = 1;
          break;
        }
        sub[ch] = s1[i] - 'a';
        used[s1[i] - 'a'] = 1;
      }
    }
    if (gg) {
      puts("NO");
    } else {
      int cur = 0;
      for (int i = 0; i < k; ++i) {
        if (sub[i] == -1) {
          while (used[cur]) cur++;
          sub[i] = cur;
          used[cur] = 1;
        }
      }
      puts("YES");
      for (int i = 0; i < k; ++i) ans[i] = sub[i] + 'a';
      ans[k] = '\0';
      printf("%s\n", ans);
    }
  }
  return 0;
}
