#include <bits/stdc++.h>
using namespace std;
long long gcd(long long n, long long m) { return m == 0 ? n : gcd(m, n % m); }
long long T, n, k, a[1000010], b[1000010], c[1000010], vis[27], tmp[27];
char s[1000010];
bool used[27];
void doit() {
  printf("YES\n");
  for (long long i = 1; i <= k; i++)
    if (!vis[i]) {
      for (long long x = 1; x <= k; x++)
        if (!used[x]) {
          vis[i] = x, used[x] = 1;
          break;
        }
    }
  for (long long i = 1; i <= k; i++) putchar(vis[i] + 'a' - 1);
  printf("\n");
}
void PU(long long flag) {
  if (flag)
    doit();
  else
    puts("NO");
  return;
}
signed main() {
  cin >> T;
  while (T--) {
    cin >> k;
    scanf("%s", s + 1);
    n = strlen(s + 1);
    for (long long i = 1; i <= n; i++) a[i] = s[i] - 'a' + 1;
    scanf("%s", s + 1);
    for (long long i = 1; i <= n; i++) b[i] = s[i] - 'a' + 1;
    scanf("%s", s + 1);
    for (long long i = 1; i <= n; i++) c[i] = s[i] - 'a' + 1;
    memset(vis, 0, sizeof(vis));
    memset(used, 0, sizeof(used));
    bool flag = 0;
    for (long long i = 1; i <= n; i++) {
      if (!vis[a[i]]) {
        for (long long x = c[i] - 1; x >= 1; x--)
          if (!used[x]) {
            for (long long j = 1; j <= k; j++) tmp[j] = vis[j];
            vis[a[i]] = x;
            used[x] = 1;
            bool islim = 1;
            flag = 1;
            for (long long j = 1; j <= n; j++) {
              if (vis[a[j]] && vis[a[j]] > b[j]) islim = 0;
              if (islim && vis[a[j]] && vis[a[j]] < b[j]) {
                flag = 0;
                break;
              }
              if (!vis[a[j]]) {
                if (!islim) {
                  for (long long x = k; x >= 1; x--)
                    if (!used[x]) {
                      vis[a[j]] = x, used[x] = 1;
                      break;
                    }
                } else {
                  bool f = 1;
                  for (long long x = k; x >= 1; x--)
                    if (!used[x]) {
                      if (x < b[j])
                        f = 0;
                      else
                        vis[a[j]] = x, used[x] = 1, islim = x == b[j];
                      break;
                    }
                  if (!f) {
                    flag = 0;
                    break;
                  }
                }
              }
            }
            if (flag) break;
            memset(used, 0, sizeof(used));
            for (long long j = 1; j <= k; j++) {
              vis[j] = tmp[j];
              if (vis[j]) used[vis[j]] = 1;
            }
            break;
          }
        if (flag) break;
        if (!used[c[i]])
          vis[a[i]] = c[i], used[c[i]] = 1;
        else
          break;
      }
      if (vis[a[i]] && (vis[a[i]] < c[i] || vis[a[i]] == c[i] && i == n)) {
        bool islim = 1;
        flag = 1;
        for (long long j = 1; j <= n; j++) {
          if (vis[a[j]] && vis[a[j]] > b[j]) islim = 0;
          if (islim && vis[a[j]] && vis[a[j]] < b[j]) {
            flag = 0;
            break;
          }
          if (!vis[a[j]]) {
            if (!islim) {
              for (long long x = k; x >= 1; x--)
                if (!used[x]) {
                  vis[a[j]] = x, used[x] = 1;
                  break;
                }
            } else {
              bool f = 1;
              for (long long x = k; x >= 1; x--)
                if (!used[x]) {
                  if (x < b[j])
                    f = 0;
                  else
                    vis[a[j]] = x, used[x] = 1, islim = x == b[j];
                  break;
                }
              if (!f) {
                flag = 0;
                break;
              }
            }
          }
        }
        break;
      }
      if (vis[a[i]] && vis[a[i]] > c[i]) break;
      if (flag) break;
    }
    PU(flag);
  }
  return 0;
}
