#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int T, n, K, h[30];
char s[maxn], a[maxn], b[maxn];
bool pd[30];
char num(char x) { return x - 'a' + 1; }
char let(char x) { return x + 'a' - 1; }
bool dfs(int x, int pdl, int pdr) {
  if (x > n || (pdl && pdr)) return 1;
  if (!h[s[x]]) {
    int l, r;
    if (pdl)
      l = 1;
    else
      l = a[x];
    if (pdr)
      r = K;
    else
      r = b[x];
    for (int i = l; i <= r; i++)
      if (!pd[i]) {
        h[s[x]] = i, pd[i] = 1;
        if (dfs(x + 1, pdl | (i > a[x]), pdr | (i < b[x]))) return 1;
        h[s[x]] = pd[i] = 0;
      }
  } else {
    if ((pdl == 0 && h[s[x]] < a[x]) || (pdr == 0 && h[s[x]] > b[x])) return 0;
    return dfs(x + 1, pdl | (h[s[x]] > a[x]), pdr | (h[s[x]] < b[x]));
  }
  return 0;
}
int main() {
  scanf("%d", &T);
  while (T--) {
    memset(h, 0, sizeof(h));
    memset(pd, 0, sizeof(pd));
    scanf("%d", &K);
    scanf("%s", s + 1), scanf("%s", a + 1), scanf("%s", b + 1);
    n = strlen(s + 1);
    for (int i = 1; i <= n; i++)
      s[i] = num(s[i]), a[i] = num(a[i]), b[i] = num(b[i]);
    if (!dfs(1, 0, 0))
      printf("NO\n");
    else {
      printf("YES\n");
      for (int i = 1; i <= K; i++)
        if (!h[i])
          for (int j = 1; j <= K; j++)
            if (!pd[j]) {
              pd[j] = 1, h[i] = j;
              break;
            }
      for (int i = 1; i <= K; i++) putchar(let(h[i]));
      puts("");
    }
  }
  return 0;
}
