#include <bits/stdc++.h>
using namespace std;
int tot = 1;
int k;
int ans[101];
bool markx[101], marky[101], mx[101], my[101];
int as[101];
char s[1000005], a[1000005], b[1000005];
int p[1000005], pp[1000005];
int e[2000005], nxt[2000005], g[2000005];
int N;
void add(int u, int v) {
  e[tot] = v;
  nxt[tot] = g[u];
  g[u] = tot++;
}
bool check(char* x, char* y) {
  for (int i = 0; i < N; i++)
    if (x[i] < y[i])
      return true;
    else if (x[i] > y[i])
      return false;
  return true;
}
void Print() {
  int cur = 0;
  for (int i = 0; i < k; i++)
    if (ans[i] == -1) {
      while (cur < k && marky[cur]) ++cur;
      if (cur == k) assert(false);
      marky[cur] = true;
      markx[i] = true;
      ans[i] = cur;
    }
  printf("YES\n");
  for (int i = 0; i < k; i++) printf("%c", ans[i] + 'a');
  printf("\n");
}
bool Worka(int idx) {
  if (p[idx] == -1 && marky[a[idx] - 'a']) return false;
  int tmp = s[idx] - 'a';
  for (int i = 0; i < 26; i++)
    mx[i] = markx[i], my[i] = marky[i], as[i] = ans[i];
  for (int i = 0; i < N; i++) pp[i] = p[i];
  marky[a[idx] - 'a'] = true;
  markx[tmp] = true;
  ans[tmp] = a[idx] - 'a';
  for (int j = g[tmp]; j; j = nxt[j]) p[e[j]] = a[idx] - 'a';
  for (int i = idx + 1; i < N; i++) {
    if (p[i] == -1) {
      int st = a[i] - 'a';
      for (int j = st + 1; j < k; j++)
        if (marky[j] == false) {
          markx[s[i] - 'a'] = true;
          marky[j] = true;
          ans[s[i] - 'a'] = j;
          for (int kk = g[s[i] - 'a']; kk; kk = nxt[kk]) p[e[kk]] = j;
          Print();
          return true;
        }
      if (marky[st] == true) {
        for (int j = 0; j < 26; j++)
          markx[j] = mx[j], marky[j] = my[j], ans[j] = as[j];
        for (int j = 0; j < N; j++) p[j] = pp[j];
        return false;
      }
      markx[s[i] - 'a'] = true;
      marky[st] = true;
      ans[s[i] - 'a'] = st;
      for (int kk = g[s[i] - 'a']; kk; kk = nxt[kk]) p[e[kk]] = st;
    } else {
      if (p[i] > a[i] - 'a') {
        Print();
        return true;
      } else if (p[i] < a[i] - 'a') {
        for (int j = 0; j < 26; j++)
          markx[j] = mx[j], marky[j] = my[j], ans[j] = as[j];
        for (int j = 0; j < N; j++) p[j] = pp[j];
        return false;
      }
    }
  }
  Print();
  return true;
}
bool Workb(int idx) {
  if (p[idx] == -1 && marky[b[idx] - 'a']) return false;
  int tmp = s[idx] - 'a';
  for (int i = 0; i < 26; i++)
    mx[i] = markx[i], my[i] = marky[i], as[i] = ans[i];
  for (int i = 0; i < N; i++) pp[i] = p[i];
  marky[b[idx] - 'a'] = true;
  markx[tmp] = true;
  ans[tmp] = b[idx] - 'a';
  for (int j = g[tmp]; j; j = nxt[j]) p[e[j]] = b[idx] - 'a';
  for (int i = idx + 1; i < N; i++) {
    if (p[i] == -1) {
      int st = b[i] - 'a';
      for (int j = st - 1; j >= 0; j--)
        if (marky[j] == false) {
          markx[s[i] - 'a'] = true;
          marky[j] = true;
          ans[s[i] - 'a'] = j;
          for (int kk = g[s[i] - 'a']; kk; kk = nxt[kk]) p[e[kk]] = j;
          Print();
          return true;
        }
      if (marky[st] == true) {
        for (int j = 0; j < 26; j++)
          markx[j] = mx[j], marky[j] = my[j], ans[j] = as[j];
        for (int j = 0; j < N; j++) p[j] = pp[j];
        return false;
      }
      markx[s[i] - 'a'] = true;
      marky[st] = true;
      ans[s[i] - 'a'] = st;
      for (int kk = g[s[i] - 'a']; kk; kk = nxt[kk]) p[e[kk]] = st;
    } else {
      if (p[i] < b[i] - 'a') {
        Print();
        return true;
      } else if (p[i] > b[i] - 'a') {
        for (int j = 0; j < 26; j++)
          markx[j] = mx[j], marky[j] = my[j], ans[j] = as[j];
        for (int j = 0; j < N; j++) p[j] = pp[j];
        return false;
      }
    }
  }
  Print();
  return true;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &k);
    scanf("%s", s);
    scanf("%s", a);
    scanf("%s", b);
    tot = 1;
    for (int i = 0; i < k; i++)
      markx[i] = false, marky[i] = false, ans[i] = -1, g[i] = 0;
    N = (int)strlen(a);
    for (int i = 0; i < N; i++) g[i] = 0, p[i] = -1;
    int idx = N;
    for (int i = 0; i < N; i++)
      if (a[i] != b[i]) {
        idx = i;
        break;
      }
    for (int i = 0; i < N; i++) add(s[i] - 'a', i);
    bool ok = false;
    for (int i = 0; i < idx; i++) {
      if (p[i] == -1) {
        p[i] = a[i] - 'a';
        int tmp = s[i] - 'a';
        if (markx[tmp] || marky[p[i]]) {
          ok = true;
          break;
        }
        markx[tmp] = true;
        marky[p[i]] = true;
        ans[tmp] = p[i];
        for (int j = g[tmp]; j; j = nxt[j]) p[e[j]] = p[i];
      } else if (p[i] != a[i] - 'a') {
        ok = true;
        break;
      }
    }
    if (ok)
      printf("NO\n");
    else {
      if (idx == N) {
        Print();
      } else {
        if (p[idx] != -1) {
          if (p[idx] < a[idx] - 'a' || p[idx] > b[idx] - 'a')
            printf("NO\n");
          else if (p[idx] > a[idx] - 'a' && p[idx] < b[idx] - 'a') {
            Print();
          } else if (p[idx] == a[idx] - 'a') {
            if (Worka(idx) == false) printf("NO\n");
          } else {
            if (Workb(idx) == false) printf("NO\n");
          }
        } else if (a[idx] - 'a' == b[idx] - 'a' + 1) {
          if (Worka(idx) == false) {
            if (Workb(idx) == false) printf("NO\n");
          }
        } else {
          bool mark = false;
          for (int j = a[idx] - 'a' + 1; j < b[idx] - 'a'; j++)
            if (marky[j] == false) {
              int tmp = s[idx] - 'a';
              marky[j] = true;
              markx[tmp] = true;
              ans[tmp] = j;
              for (int kk = g[tmp]; kk; kk = nxt[kk]) p[e[kk]] = j;
              Print();
              mark = true;
              break;
            }
          if (mark == false) {
            if (Worka(idx) == false) {
              if (Workb(idx) == false) {
                printf("NO\n");
              }
            }
          }
        }
      }
    }
  }
  return 0;
}
