#include <bits/stdc++.h>
using namespace std;
struct Rep {
  char link[26];
  bool vis[26];
  Rep() {
    memset(link, 255, sizeof(link));
    memset(vis, 0, sizeof(vis));
  }
  bool check(char x, char y) {
    return (link[x] == y) || (link[x] == -1 && !vis[y]);
  }
  void add(char x, char y) {
    link[x] = y;
    vis[y] = 1;
  }
  void output(int k) {
    int cnt = 0;
    for (int i = 0; i < k; i++)
      if (link[i] == -1) {
        while (vis[cnt]) cnt++;
        vis[cnt] = 1;
        link[i] = cnt;
      }
    puts("YES");
    for (int i = 0; i < k; i++) putchar(link[i] + 'a');
    printf("\n");
  }
};
char s1[1000005], s2[1000005], s3[1000005];
bool solve(int n, int k) {
  Rep fir;
  int d = 1;
  while (d <= n && s1[d] == s2[d]) {
    if (!fir.check(s3[d], s1[d])) return 0;
    fir.add(s3[d], s1[d]);
    d++;
  }
  if (d > n) {
    fir.output(k);
    return 1;
  }
  for (int i = s1[d] + 1; i < s2[d]; i++)
    if (fir.check(s3[d], i)) {
      fir.add(s3[d], i);
      fir.output(k);
      return 1;
    }
  if (fir.check(s3[d], s1[d])) {
    Rep now = fir;
    now.add(s3[d], s1[d]);
    bool ok = 1;
    for (int i = d + 1; i <= n; i++) {
      for (int j = s1[i] + 1; j < k; j++)
        if (now.check(s3[i], j)) {
          now.add(s3[i], j);
          now.output(k);
          return 1;
        }
      if (!now.check(s3[i], s1[i])) {
        ok = 0;
        break;
      }
      now.add(s3[i], s1[i]);
    }
    if (ok) {
      now.output(k);
      return 1;
    }
  }
  if (fir.check(s3[d], s2[d])) {
    Rep now = fir;
    now.add(s3[d], s2[d]);
    bool ok = 1;
    for (int i = d + 1; i <= n; i++) {
      for (int j = 0; j < s2[i]; j++)
        if (now.check(s3[i], j)) {
          now.add(s3[i], j);
          now.output(k);
          return 1;
        }
      if (!now.check(s3[i], s2[i])) {
        ok = 0;
        break;
      }
      now.add(s3[i], s2[i]);
    }
    if (ok) {
      now.output(k);
      return 1;
    }
  }
  return 0;
}
int main() {
  int cases;
  scanf("%d", &cases);
  for (; cases; cases--) {
    int k;
    scanf("%d", &k);
    scanf("%s%s%s", s3 + 1, s1 + 1, s2 + 1);
    int n = strlen(s1 + 1);
    for (int i = 1; i <= n; i++) {
      s1[i] -= 'a';
      s2[i] -= 'a';
      s3[i] -= 'a';
    }
    if (!solve(n, k)) puts("NO");
  }
  return 0;
}
