#include <bits/stdc++.h>
using namespace std;
char ch[1000020], a[1000020], b[1000020], ans[1000020], tmp[50];
int n, T, cnt[50], cur[50], k, tag[50];
bool check(int t1, int t2, int x) {
  if (!t1 && !t2) {
    return 1;
  }
  if (x == n + 1) return 1;
  int c = ch[x] - 'a';
  if (tmp[c]) {
    if (t1 && tmp[c] < a[x]) return 0;
    if (t2 && tmp[c] > b[x]) return 0;
    return check(t1 & (tmp[c] == a[x]), t2 & (b[x] == tmp[c]), x + 1);
  }
  if (t1) {
    if (!tag[a[x] - 'a'] && (!t2 || b[x] >= a[x])) {
      tmp[c] = a[x];
      tag[a[x] - 'a'] = 1;
      if (check(1, t2 & (b[x] == tmp[c]), x + 1)) return 1;
      tmp[c] = 0, tag[a[x] - 'a'] = 0;
    }
    if (t2) {
      for (register int i = a[x] - 'a' + 1; i <= b[x] - 'a'; i++)
        if (!tag[i]) {
          tmp[c] = i + 'a';
          tag[i] = 1;
          return check(0, b[x] == tmp[c], x + 1);
        }
      return 0;
    }
    for (register int i = a[x] - 'a' + 1; i <= k; i++)
      if (!tag[i]) {
        tmp[c] = i + 'a';
        tag[i] = 1;
        return 1;
      }
    return 0;
  }
  for (register int i = 0; i <= b[x] - 'a'; i++)
    if (!tag[i]) {
      tmp[c] = i + 'a';
      tag[i] = 1;
      return check(0, b[x] == tmp[c], x + 1);
    }
  return 0;
}
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &k), k--;
    scanf("%s %s %s", ch + 1, a + 1, b + 1);
    n = strlen(ch + 1);
    memset(tmp, 0, sizeof(tmp));
    memset(tag, 0, sizeof(tag));
    if (check(1, 1, 1)) {
      puts("YES");
      for (register int i = 0; i <= k; i++) {
        if (!tmp[i]) {
          for (register int j = 0; j <= k; j++)
            if (!tag[j]) {
              tmp[i] = j + 'a', tag[j] = 1;
              break;
            }
        }
      }
      for (register int i = 0; i <= k; i++) putchar(tmp[i]);
      puts("");
    } else
      puts("NO");
  }
}
