#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int T, k, n;
char s[N], a[N], b[N];
int p[26], u[26], c[26];
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &k);
    scanf("%s%s%s", s + 1, a + 1, b + 1);
    n = strlen(s + 1);
    for (int i = 1; i <= n; i++) s[i] -= 'a', a[i] -= 'a', b[i] -= 'a';
    for (int i = 0; i <= k - 1; i++) p[i] = -1, u[i] = -1, c[i] = 0;
    int x = 1;
    for (; x <= n; x++) {
      c[s[x]]++;
      if (p[s[x]] == a[x]) continue;
      if (p[s[x]] == -1 && u[a[x]] == -1) {
        p[s[x]] = a[x];
        u[a[x]] = s[x];
        continue;
      }
      break;
    }
    if (x <= n) {
      c[s[x]]--;
      int xx = x;
      for (; x > 0; x--) {
        if (p[s[x]] > a[x]) break;
        if (x != xx) {
          c[s[x]]--;
          p[s[x]] = !c[s[x]] ? -1 : p[s[x]];
          u[a[x]] = !c[s[x]] ? -1 : u[a[x]];
        }
        if (p[s[x]] != -1) continue;
        int ye = -1;
        for (int j = a[x] + 1; j <= k - 1; j++)
          if (u[j] == -1) {
            ye = j;
            break;
          }
        if (ye == -1) continue;
        p[s[x]] = ye;
        u[ye] = s[x];
        break;
      }
      if (x == 0) {
        printf("NO\n");
        continue;
      }
      for (x++; x <= n; x++) {
        if (p[s[x]] != -1) continue;
        int ye = -1;
        for (int j = 0; j <= k - 1; j++)
          if (u[j] == -1) {
            ye = j;
            break;
          }
        p[s[x]] = ye;
        u[ye] = s[x];
      }
    }
    for (int i = 0; i <= k - 1; i++)
      if (p[i] == -1) {
        for (int j = 0; j <= k - 1; j++)
          if (u[j] == -1) {
            p[i] = j;
            u[j] = i;
            break;
          }
      }
    int ans = 1;
    for (int i = 1; i <= n; i++) {
      s[i] = p[s[i]];
      if (s[i] < b[i]) break;
      if (s[i] > b[i]) {
        ans = 0;
        break;
      }
    }
    if (!ans)
      puts("NO");
    else {
      puts("YES");
      for (int i = 0; i <= k - 1; i++) putchar('a' + p[i]);
      puts("");
    }
  }
}
