#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000000;
const int MAX_K = 26;
char s[MAX_N + 4], a[MAX_N + 4], b[MAX_N + 4];
char t[MAX_N + 4];
int tls[MAX_K], fps[MAX_K];
int rollback(int k, vector<pair<int, int> > &q) {
  while (!q.empty()) {
    pair<int, int> p = q.back();
    q.pop_back();
    int f = p.first, c = p.second, si = s[f] - 'a';
    tls[si] = -1;
    fps[c] = -1;
    c++;
    while (c < k && fps[c] >= 0) c++;
    if (c < k) {
      tls[si] = c;
      fps[c] = f;
      return f + 1;
    }
  }
  return 0;
}
int main() {
  int tn;
  scanf("%d", &tn);
  while (tn--) {
    int k;
    scanf("%d%s%s%s", &k, s, a, b);
    int n = strlen(s);
    memset(tls, -1, sizeof(tls));
    memset(fps, -1, sizeof(fps));
    vector<pair<int, int> > q;
    int m = 0;
    while (m < n) {
      int si = s[m] - 'a', ai = a[m] - 'a';
      if (tls[si] < 0) {
        int ci = ai;
        while (ci < k && fps[ci] >= 0) ci++;
        if (ci < k) {
          tls[si] = ci;
          fps[ci] = m++;
          q.push_back(pair<int, int>(fps[ci], ci));
          if (ci > ai) break;
        } else {
          m = rollback(k, q);
          break;
        }
      } else {
        if (tls[si] < ai) {
          m = rollback(k, q);
          break;
        }
        m++;
        if (tls[si] > ai) break;
      }
    }
    if (m <= 0) {
      puts("NO");
      continue;
    }
    for (; m < n; m++) {
      int si = s[m] - 'a', ai = a[m] - 'a';
      if (tls[si] < 0) {
        int c = 0;
        for (; c < k; c++)
          if (fps[c] < 0) break;
        tls[si] = c;
        fps[c] = m;
      }
    }
    for (int i = 0; i < n; i++) t[i] = tls[s[i] - 'a'] + 'a';
    t[n] = '\0';
    if (strcmp(t, b) > 0) {
      puts("NO");
      continue;
    }
    for (int i = 0, c = 0; i < k; i++)
      if (tls[i] < 0) {
        while (fps[c] >= 0) c++;
        tls[i] = c++;
      }
    puts("YES");
    for (int i = 0; i < k; i++) putchar(tls[i] + 'a');
    putchar('\n');
  }
  return 0;
}
