#include <bits/stdc++.h>
const int N = 3010000;
char s[N], a[N], b[N];
int n, m;
int trans[26], from[26];
void solve() {
  scanf("%d", &m);
  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] -= 'a', a[i] -= 'a', b[i] -= 'a';
  for (int i = 0; i < m; i++) trans[i] = from[i] = -1;
  int ind = -1;
  for (int i = 0; i <= n; i++) {
    if (i == n) {
      ind = i;
      break;
    }
    if (~trans[s[i + 1]] && trans[s[i + 1]] < a[i + 1]) break;
    bool flag = 0;
    if (~trans[s[i + 1]])
      flag = trans[s[i + 1]] > a[i + 1];
    else
      for (int j = a[i + 1] + 1; j < m; j++)
        if (from[j] == -1) flag = 1;
    if (flag) ind = i;
    if (~trans[s[i + 1]] && trans[s[i + 1]] != a[i + 1]) break;
    if (~from[a[i + 1]] && from[a[i + 1]] != s[i + 1]) break;
    trans[s[i + 1]] = a[i + 1];
    from[a[i + 1]] = s[i + 1];
  }
  if (ind == -1) return void(printf("NO\n"));
  for (int i = 0; i < m; i++) trans[i] = from[i] = -1;
  for (int i = 1; i <= ind; i++) trans[s[i]] = a[i], from[a[i]] = s[i];
  if (ind < n && trans[s[ind + 1]] == -1)
    for (int i = a[ind + 1] + 1; i < m; i++)
      if (from[i] == -1) {
        trans[s[ind + 1]] = i, from[i] = s[ind + 1];
        break;
      }
  for (int i = ind + 2; i <= n; i++)
    if (trans[s[i]] == -1)
      for (int j = 0; j < m; j++)
        if (from[j] == -1) {
          trans[s[i]] = j, from[j] = s[i];
          break;
        }
  for (int i = 0; i < m; i++)
    if (trans[i] == -1)
      for (int j = 0; j < m; j++)
        if (from[j] == -1) {
          trans[i] = j, from[j] = i;
          break;
        }
  bool flag = 1;
  for (int i = 1; i <= n; i++)
    if (trans[s[i]] != b[i]) {
      flag = trans[s[i]] < b[i];
      break;
    }
  if (!flag)
    printf("NO");
  else
    for (int i = (printf("YES\n"), 0); i < m; i++) printf("%c", trans[i] + 'a');
  printf("\n");
}
int main() {
  int T;
  for (scanf("%d", &T); T--; solve())
    ;
  return 0;
}
