#include <bits/stdc++.h>
using namespace std;
int read() {
  int X = 0, p = 1;
  char c = getchar();
  for (; c > '9' || c < '0'; c = getchar())
    if (c == '-') p = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) X = X * 10 + c - '0';
  return X * p;
}
const int N = 1e6 + 5;
int n, m;
int ans[N], used[N];
char s[N], a[N], b[N];
void output() {
  puts("YES");
  for (int i = 1, j = 1; i <= m; ++i)
    if (!used[i]) {
      while (ans[j]) j++;
      ans[j] = i;
      used[i] = 1;
    }
  for (int i = 1; i <= m; ++i) putchar('a' + ans[i] - 1);
  puts("");
}
int work(int pos, bool lima, bool limb) {
  if (pos == n + 1 || (!lima && !limb)) {
    output();
    return 1;
  }
  if (ans[s[pos]]) {
    if (lima && ans[s[pos]] < a[pos]) return 0;
    if (limb && ans[s[pos]] > b[pos]) return 0;
    if (work(pos + 1, lima && ans[s[pos]] == a[pos],
             limb && ans[s[pos]] == b[pos]))
      return 1;
    else
      return 0;
  }
  for (int i = 1; i <= m; ++i)
    if (!used[i]) {
      if (lima && i <= a[pos]) continue;
      if (limb && i >= b[pos]) continue;
      used[i] = 1;
      ans[s[pos]] = i;
      output();
      return 1;
    }
  if (lima && !used[a[pos]]) {
    used[a[pos]] = 1;
    ans[s[pos]] = a[pos];
    if (work(pos + 1, lima, limb && a[pos] == b[pos])) return 1;
    used[a[pos]] = 0;
    ans[s[pos]] = 0;
  }
  if (limb && !used[b[pos]]) {
    used[b[pos]] = 1;
    ans[s[pos]] = b[pos];
    if (work(pos + 1, lima && a[pos] == b[pos], limb)) return 1;
    used[b[pos]] = 0;
    ans[s[pos]] = 0;
  }
  return 0;
}
int main() {
  int T = read();
  for (; T; T--) {
    m = read();
    scanf("%s%s%s", s + 1, a + 1, b + 1);
    n = strlen(s + 1);
    for (int i = 1; i <= m; ++i) ans[i] = used[i] = 0;
    for (int i = 1; i <= n; ++i) {
      s[i] = s[i] - 'a' + 1;
      a[i] = a[i] - 'a' + 1;
      b[i] = b[i] - 'a' + 1;
    }
    if (!work(1, 1, 1)) puts("NO");
    memset(s, 0, sizeof(int) * (n + 1));
    memset(a, 0, sizeof(int) * (n + 1));
    memset(b, 0, sizeof(int) * (n + 1));
  }
}
