#include <bits/stdc++.h>
using namespace std;
const int maxi = 1e6 + 10;
string s, a, b, rez;
char ch[maxi];
int k;
int res[200], cnt[200];
void sredi() {
  for (int i = 'a'; i < 'a' + k; i++) {
    res[i] = 0;
    cnt[i] = 0;
  }
}
void popuni() {
  int curx = 'a';
  int cury = 'a';
  while (curx < 'a' + k) {
    if (!res[curx]) {
      while (cnt[cury]) cury++;
      res[curx] = cury;
      cnt[cury] = curx;
    }
    curx++;
  }
  return;
}
void solve() {
  scanf("%d", &k);
  scanf("%s", &ch);
  s.assign(ch);
  scanf("%s", &ch);
  a.assign(ch);
  scanf("%s", &ch);
  b.assign(ch);
  int n = s.size();
  sredi();
  int ok = 1;
  for (int i = 0; i < n; i++)
    if (a[i] != b[i]) {
      if (b[i] - a[i] == 1) ok = 0;
      if (res[s[i]] && (res[s[i]] <= a[i] || res[s[i]] >= b[i])) ok = 0;
      if (!res[s[i]]) {
        int nasao = 0;
        for (int j = a[i] + 1; j < b[i]; j++)
          if (!cnt[j]) {
            res[s[i]] = j;
            cnt[j] = s[i];
            nasao = 1;
            break;
          }
        if (nasao) break;
      }
      if (!res[s[i]]) ok = 0;
      break;
    } else {
      if (cnt[a[i]] && cnt[a[i]] != s[i]) ok = 0;
      if (res[s[i]] && res[s[i]] != a[i]) ok = 0;
      cnt[a[i]] = s[i];
      res[s[i]] = a[i];
      if (!ok) break;
    }
  if (ok) {
    printf("YES\n");
    popuni();
    for (int i = 'a'; i < 'a' + k; i++) printf("%c", res[i]);
    printf("\n");
    return;
  }
  sredi();
  int manjiB = 0;
  ok = 1;
  for (int i = 0; i < n; i++) {
    if (manjiB) {
      if (res[s[i]] && res[s[i]] > a[i]) {
        break;
      }
      if (!res[s[i]]) {
        int nasao = 0;
        for (int j = a[i] + 1; j < 'a' + k; j++)
          if (!cnt[j]) {
            res[s[i]] = j;
            cnt[j] = s[i];
            nasao = 1;
            break;
          }
        if (nasao) break;
      }
    }
    if (cnt[a[i]] && cnt[a[i]] != s[i]) ok = 0;
    if (res[s[i]] && res[s[i]] != a[i]) ok = 0;
    cnt[a[i]] = s[i];
    res[s[i]] = a[i];
    if (!manjiB) {
      if (res[s[i]] < b[i])
        manjiB = 1;
      else if (res[s[i]] > b[i]) {
        ok = 0;
      }
    }
    if (!ok) break;
  }
  if (ok) {
    printf("YES\n");
    popuni();
    for (int i = 'a'; i < 'a' + k; i++) printf("%c", res[i]);
    printf("\n");
    return;
  }
  sredi();
  int veciA = 0;
  ok = 1;
  for (int i = 0; i < n; i++) {
    if (veciA) {
      if (res[s[i]] && res[s[i]] < b[i]) {
        break;
      }
      if (!res[s[i]]) {
        int nasao = 0;
        for (int j = b[i] - 1; j >= 'a'; j--)
          if (!cnt[j]) {
            res[s[i]] = j;
            cnt[j] = s[i];
            nasao = 1;
            break;
          }
        if (nasao) break;
      }
    }
    if (cnt[b[i]] && cnt[b[i]] != s[i]) ok = 0;
    if (res[s[i]] && res[s[i]] != b[i]) ok = 0;
    cnt[b[i]] = s[i];
    res[s[i]] = b[i];
    if (!veciA) {
      if (res[s[i]] > a[i])
        veciA = 1;
      else if (res[s[i]] < a[i]) {
        ok = 0;
      }
    }
    if (!ok) break;
  }
  if (ok) {
    printf("YES\n");
    popuni();
    for (int i = 'a'; i < 'a' + k; i++) printf("%c", res[i]);
    printf("\n");
    return;
  }
  printf("NO\n");
  return;
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
