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