#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 3;
int t, n, k, maxc;
char s[N], a[N], b[N], c[N];
map<char, char> f;
bool vis[26];
bool dfs(int u, bool up) {
  if (u > n) return 1;
  int minc = up ? a[u] : 'a';
  if (!f[s[u]]) {
    for (int i = minc; i <= maxc; i++)
      if (!vis[i - 'a']) {
        vis[i - 'a'] = 1;
        int used = f[s[u]];
        f[s[u]] = i;
        if (dfs(u + 1, up & (i == minc))) return 1;
        f[s[u]] = used;
        vis[i - 'a'] = 0;
      }
    return 0;
  } else if (f[s[u]] < minc || f[s[u]] > maxc)
    return 0;
  else
    return dfs(u + 1, up & (f[s[u]] == minc));
}
void solve() {
  scanf("%d", &k);
  maxc = 'a' + k - 1;
  scanf("%s\n%s\n%s", s + 1, a + 1, b + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++)
    if (s[i] > maxc) {
      printf("NO\n");
      return;
    }
  memset(vis, 0, sizeof vis);
  f.clear();
  if (!dfs(1, 1)) {
    printf("NO\n");
    return;
  }
  for (int i = 1; i <= n; i++) c[i] = f[s[i]];
  c[n + 1] = '\0';
  if (strcmp(c + 1, b + 1) > 0) {
    printf("NO\n");
    return;
  }
  printf("YES\n");
  for (int i = 0; i < k; i++)
    if (!f[i + 'a'])
      for (int j = 0; j < k; j++)
        if (!vis[j]) {
          vis[j] = 1;
          f[i + 'a'] = j + 'a';
          break;
        }
  for (int i = 0; i < k; i++) putchar(f[i + 'a']);
  putchar('\n');
}
int main() {
  scanf("%d", &t);
  while (t--) solve();
  return 0;
}
