#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= f;
}
inline unsigned int R() {
  static unsigned int seed = 416;
  return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13;
}
const int N = 1020000;
int n, k, buc[27], rev[27];
char s[N], a[N], b[N], t[N];
bool gg;
void calc(int p) {
  if (buc[s[p] - 'a'] >= 0)
    gg |= buc[s[p] - 'a'] != t[p];
  else {
    if (rev[t[p] - 'a'] >= 0) {
      gg = 1;
      return;
    }
    buc[s[p] - 'a'] = t[p];
    rev[t[p] - 'a'] = s[p];
  }
}
void getmax(int i) {
  for (; i <= n; i++) {
    if (buc[s[i] - 'a'] >= 0)
      t[i] = buc[s[i] - 'a'];
    else {
      for (register int j = k - 1; j >= 0; j--)
        if (rev[j] < 0) {
          t[i] = 'a' + j, calc(i);
          break;
        }
    }
  }
}
void getmin(int i) {
  for (; i <= n; i++) {
    if (buc[s[i] - 'a'] >= 0)
      t[i] = buc[s[i] - 'a'];
    else {
      for (register int j = 0; j <= k - 1; j++)
        if (rev[j] < 0) {
          t[i] = 'a' + j, calc(i);
          break;
        }
    }
  }
}
bool ck() {
  for (register int i = 1; i <= n; i++)
    if (t[i] != a[i]) {
      if (t[i] < a[i]) return 0;
      break;
    }
  for (register int i = 1; i <= n; i++)
    if (t[i] != b[i]) {
      if (t[i] > b[i]) return 0;
      break;
    }
  return 1;
}
int main() {
  int T;
  read(T);
  while (T--) {
    read(k);
    scanf("%s%s%s", s + 1, a + 1, b + 1);
    n = strlen(s + 1);
    memset(buc, -1, sizeof(buc));
    memset(rev, -1, sizeof(rev));
    int p = 1;
    gg = 0;
    while (p <= n && a[p] == b[p]) {
      t[p] = a[p];
      calc(p);
      p++;
    }
    if (p <= n && !gg) {
      bool fd = 0;
      for (register int i = a[p] + 1; i <= b[p] - 1; i++) {
        gg = 0;
        t[p] = i;
        calc(p);
        if (gg) {
          gg = 0;
          t[p] = 0;
        } else {
          fd = 1;
          getmax(p + 1);
          break;
        }
      }
      if (!fd) {
        int tmp[27], tmp1[27];
        memcpy(tmp, buc, sizeof(buc));
        memcpy(tmp1, rev, sizeof(rev));
        gg = 0;
        t[p] = a[p];
        calc(p);
        getmax(p + 1);
        if (gg || !ck()) {
          memcpy(buc, tmp, sizeof(tmp));
          memcpy(rev, tmp1, sizeof(tmp1));
          gg = 0;
          t[p] = b[p];
          calc(p);
          getmin(p + 1);
        }
      }
    }
    if (!gg && !ck()) gg = 1;
    if (gg)
      puts("NO");
    else {
      puts("YES");
      for (register int i = 0; i <= k - 1; i++)
        if (buc[i] < 0)
          for (register int j = 0; j <= k - 1; j++)
            if (rev[j] < 0) {
              buc[i] = 'a' + j;
              rev[j] = 'a' + i;
              break;
            }
      for (register int i = 0; i <= k - 1; i++)
        assert(buc[i] >= 'a' && buc[i] <= 'a' + k - 1);
      for (register int i = 0; i <= k - 1; i++) printf("%c", buc[i]);
      puts("");
    }
  }
  return 0;
}
