#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') {
    x = 10 * x + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int maxn = 1000100;
int tc, k, len;
char s[maxn], a[maxn], b[maxn];
char dic[30];
bool used[30];
void output() {
  puts("YES");
  int num = 0;
  for (register int j = (int)(0); j <= (int)(k - 1); j++) {
    if (dic[j] == ' ') {
      while (used[num]) num++;
      dic[j] = char(num + 'a');
      num++;
    }
    putchar(dic[j]);
  }
  puts("");
}
bool solve(int i, bool f1, bool f2) {
  if (i > len || (f1 && f2)) {
    output();
    return true;
  }
  if (dic[s[i] - 'a'] != ' ') {
    if (!f1 && dic[s[i] - 'a'] < a[i]) return false;
    if (!f2 && dic[s[i] - 'a'] > b[i]) return false;
    return solve(i + 1, f1 | (dic[s[i] - 'a'] > a[i]),
                 f2 | (dic[s[i] - 'a'] < b[i]));
  }
  for (register int j = (int)(0); j <= (int)(k - 1); j++) {
    char c = (char)('a' + j);
    if (used[c - 'a']) continue;
    if (!f1 && c < a[i]) continue;
    if (!f2 && c > b[i]) continue;
    used[c - 'a'] = 1;
    dic[s[i] - 'a'] = c;
    if (solve(i + 1, f1 | (c > a[i]), f2 | (c < b[i]))) return true;
    used[c - 'a'] = 0;
    dic[s[i] - 'a'] = ' ';
  }
  return false;
}
void work() {
  tc = read();
  while (tc--) {
    k = read();
    scanf("%s %s %s", s + 1, a + 1, b + 1);
    len = strlen(s + 1);
    for (register int i = (int)(0); i <= (int)(k - 1); i++) dic[i] = ' ';
    memset(used, 0, sizeof(used));
    if (!solve(1, 0, 0)) puts("NO");
  }
}
int main() { work(); }
