#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse3", "sse2", "sse")
#pragma GCC optimize("inline", "fast-math", "unroll-loops", \
                     "no-stack-protector")
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
const int MAXN = 2e6 + 5000;
const long double eps = (1e-12);
const int logn = 21;
const double Pi = acos(-1.0);
const long long pp = 1000000000 + 7;
int lowbit(int x) { return x & (-x); }
const int INF = 1e9;
int n, k;
char s[MAXN];
char a[MAXN];
char b[MAXN];
bool okk = false;
bool check() {
  for (int i = 1; i <= n; i++) {
    if (a[i] == b[i]) continue;
    return a[i] < b[i];
  }
  return true;
}
int ans[MAXN];
set<int> st;
void getans() {
  okk = true;
  for (int i = 1; i <= n; i++) {
    if (ans[s[i] - 'a'] == -1) {
      auto it = st.begin();
      ans[s[i] - 'a'] = *it;
      st.erase(it);
    }
  }
  for (int i = 0; i < k; i++) {
    if (ans[i] == -1) {
      auto it = st.begin();
      ans[i] = *it;
      st.erase(it);
    }
  }
  bool ok = true;
  for (int i = 1; i <= n; i++) {
    if (ans[s[i] - 'a'] + 'a' == b[i]) continue;
    ok = ans[s[i] - 'a'] + 'a' < b[i];
    break;
  }
  if (ok) {
    printf("YES\n");
    for (int i = 0; i < k; i++) printf("%c", ans[i] + 'a');
    printf("\n");
  } else {
    printf("NO\n");
  }
}
void solver(int pos, int sta) {
  if (okk) {
    return;
  }
  if (pos == n + 1) {
    getans();
    return;
  }
  if (sta == 0) {
    getans();
  }
  int nowc = ans[s[pos] - 'a'];
  if (nowc != -1) {
    if (sta == 1) {
      if (a[pos] > nowc + 'a') {
        return;
      } else if (a[pos] == nowc + 'a') {
        solver(pos + 1, sta);
      } else {
        solver(pos + 1, 0);
      }
    } else {
      solver(pos + 1, 0);
    }
  } else {
    if (sta) {
      auto it = st.lower_bound(a[pos] - 'a');
      if (it == st.end()) {
        return;
      }
      while (okk == false && it != st.end()) {
        int nowc = *it;
        if (*it == a[pos] - 'a') {
          ans[s[pos] - 'a'] = nowc;
          st.erase(nowc);
          solver(pos + 1, sta);
          st.insert(nowc);
          ans[s[pos] - 'a'] = -1;
        } else {
          ans[s[pos] - 'a'] = nowc;
          st.erase(nowc);
          solver(pos + 1, 0);
          st.insert(nowc);
          ans[s[pos] - 'a'] = -1;
        }
        it = st.lower_bound(nowc + 1);
      }
    } else {
      auto it = st.begin();
      if (it == st.end()) {
        return;
      }
      while (it != st.end() && okk == false) {
        int nowc = *it;
        ans[s[pos] - 'a'] = nowc;
        st.erase(nowc);
        solver(pos + 1, 0);
        st.insert(nowc);
        ans[s[pos] - 'a'] = -1;
        it = st.lower_bound(nowc + 1);
      }
    }
  }
}
signed main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    okk = false;
    scanf("%d", &k);
    scanf("%s%s%s", s + 1, a + 1, b + 1);
    n = strlen(s + 1);
    if (!check()) {
      printf("NO\n");
    } else {
      st.clear();
      for (int i = 0; i < k; i++) {
        ans[i] = -1;
        st.insert(i);
      }
      solver(1, 1);
      if (!okk) {
        printf("NO\n");
      }
    }
  }
  return 0;
}
