#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
char s[N], a[N], b[N], c[N], d[N];
int n, k, f[26];
bool h[26];
bool Dfs(char *a, char *b, int i) {
  for (; i < n; ++i)
    if (f[s[i]] != -1) {
      if (f[s[i]] < a[i] || f[s[i]] > b[i]) return false;
      if (f[s[i]] > a[i] && a != c) a = c;
      if (f[s[i]] < b[i] && b != d) b = d;
    } else {
      for (int j = a[i]; j <= b[i]; ++j)
        if (!h[j]) {
          h[j] = true;
          f[s[i]] = j;
          if (Dfs(f[s[i]] > a[i] ? c : a, f[s[i]] < b[i] ? d : b, i + 1))
            return true;
          f[s[i]] = -1;
          h[j] = false;
        }
      return false;
    }
  puts("YES");
  for (int i = 0; i < k; ++i) {
    if (f[i] == -1) {
      int j = 0;
      for (; j < k && h[j]; ++j)
        ;
      h[j] = true;
      f[i] = j;
    }
    putchar(f[i] + 'a');
  }
  puts("");
  return true;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%s%s%s", &k, s, a, b), n = (int)strlen(s);
    memset(d, k - 1, n);
    memset(f, -1, sizeof(f)), memset(h, 0, sizeof(h));
    for (int i = 0; i < n; ++i) s[i] -= 'a', a[i] -= 'a', b[i] -= 'a';
    if (!Dfs(a, b, 0)) puts("NO");
  }
  return 0;
}
