#include <bits/stdc++.h>
using namespace std;
int k;
char s[1000004], a[1000004], b[1000004];
int ch[34];
bool vis[34];
bool dfs(int x, int lim, int L, int R) {
  if (x > lim) {
    puts("YES");
    for (int i = 0; i < k; i++) {
      if (ch[i] != -1) continue;
      for (int j = 0; j < k; j++) {
        if (vis[j]) continue;
        ch[i] = j;
        vis[j] = 1;
        break;
      }
    }
    for (int i = 0; i < k; i++) printf("%c", ch[i] + 'a');
    puts("");
    return 1;
  }
  int cl = 0, cr = k - 1;
  if (L) cl = a[x] - 'a';
  if (R) cr = b[x] - 'a';
  if (ch[s[x] - 'a'] == -1) {
    for (int i = cl; i <= cr; i++) {
      if (!vis[i]) {
        vis[i] = 1;
        ch[s[x] - 'a'] = i;
        if (dfs(x + 1, lim, L && (i == cl), R && (i == cr))) return 1;
        vis[i] = 0;
        ch[s[x] - 'a'] = -1;
      }
    }
  } else {
    int now = ch[s[x] - 'a'];
    if (cl <= now && now <= cr) {
      if (dfs(x + 1, lim, L && (now == cl), R && (now == cr)))
        return 1;
      else
        return 0;
    } else
      return 0;
  }
  return 0;
}
int w33ha() {
  memset(ch, -1, sizeof(ch));
  memset(vis, 0, sizeof(vis));
  scanf("%d", &k);
  scanf("%s", s + 1);
  scanf("%s", a + 1);
  scanf("%s", b + 1);
  int l = strlen(s + 1);
  if (!dfs(1, l, 1, 1)) return puts("NO"), 0;
  return 0;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) w33ha();
  return 0;
}
