#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 6;
int T;
int k;
int n;
char s[maxn], a[maxn], b[maxn];
int f[300];
int ans[300];
int tf[300], tans[300];
void nxt() {
  char c = 'a';
  for (char ch = 'a'; ch <= 'a' + k - 1; ch++)
    if (!ans[ch]) {
      while (f[c]) c++;
      ans[ch] = c++;
    }
  puts("YES");
  for (char ch = 'a'; ch <= 'a' + k - 1; ch++) printf("%c", ans[ch]);
  puts("");
}
bool dfs(int now, int typ) {
  if (typ == 1) {
    for (int i = now; i <= n; i++) {
      int l = a[i];
      if (ans[s[i]]) {
        if (ans[s[i]] < l) return 0;
        if (ans[s[i]] > l) {
          nxt();
          return 1;
        }
        continue;
      }
      for (char ch = l + 1; ch <= 'a' + k - 1; ch++)
        if (!f[ch]) {
          ans[s[i]] = ch;
          f[ch] = 1;
          nxt();
          return 1;
        }
      if (f[l]) return 0;
      ans[s[i]] = l;
      f[l] = 1;
    }
  } else {
    for (int i = now; i <= n; i++) {
      int r = b[i];
      if (ans[s[i]]) {
        if (ans[s[i]] > r) return 0;
        if (ans[s[i]] < r) {
          nxt();
          return 1;
        }
        continue;
      }
      for (char ch = 'a'; ch < r; ch++)
        if (!f[ch]) {
          ans[s[i]] = ch;
          f[ch] = 1;
          nxt();
          return 1;
        }
      if (f[r]) return 0;
      ans[s[i]] = r;
      f[r] = 1;
    }
  }
  nxt();
  return 1;
}
int main() {
  scanf("%d", &T);
  while (T--) {
    for (char ch = 'a'; ch <= 'z'; ch++) f[ch] = ans[ch] = 0;
    scanf("%d%s%s%s", &k, s + 1, a + 1, b + 1);
    n = strlen(s + 1);
    int po = 1;
    int ok = 1;
    while (po <= n && a[po] == b[po]) {
      if (ans[s[po]] && ans[s[po]] != a[po]) ok = 0;
      if (!ans[s[po]] && f[a[po]]) ok = 0;
      ans[s[po]] = a[po];
      f[a[po]] = 1;
      ++po;
    }
    if (!ok) {
      puts("NO");
      continue;
    }
    if (po > n) {
      nxt();
      continue;
    }
    if (ans[s[po]]) {
      if (ans[s[po]] > a[po] && ans[s[po]] < b[po]) {
        nxt();
        continue;
      }
      if (ans[s[po]] < a[po] || ans[s[po]] > b[po]) {
        puts("NO");
        continue;
      }
      if (ans[s[po]] == a[po]) {
        if (dfs(po + 1, 1))
          continue;
        else {
          puts("NO");
          continue;
        }
      } else {
        if (dfs(po + 1, 2))
          continue;
        else {
          puts("NO");
          continue;
        }
      }
    }
    ok = 0;
    for (char ch = a[po] + 1; ch < b[po]; ch++)
      if (!f[ch]) {
        ok = 1;
        f[ch] = 1;
        ans[s[po]] = ch;
        nxt();
        break;
      }
    if (ok) continue;
    for (char ch = 'a'; ch <= 'z'; ch++) {
      tf[ch] = f[ch];
      tans[ch] = ans[ch];
    }
    if (!f[a[po]]) {
      ans[s[po]] = a[po];
      f[a[po]] = 1;
      if (dfs(po + 1, 1)) continue;
    }
    for (char ch = 'a'; ch <= 'z'; ch++) {
      f[ch] = tf[ch];
      ans[ch] = tans[ch];
    }
    if (!f[b[po]]) {
      ans[s[po]] = b[po];
      f[b[po]] = 1;
      if (dfs(po + 1, 2))
        continue;
      else {
        puts("NO");
        continue;
      }
    }
    puts("NO");
  }
  return 0;
}
