#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int T;
int m;
int n;
char e, c[256], s[256], _c[256], _s[256];
string p, a, b;
void ReadInput() {
  cin >> m;
  cin >> p >> a >> b;
  n = p.length();
  e = 'a' + m - 1;
}
bool add(char x, char y) {
  if (c[x] != ' ' || s[y] != ' ') return c[x] == y;
  c[x] = y;
  s[y] = x;
  return true;
}
bool solve1(int u) {
  if (c[p[u]] != ' ') return a[u] < c[p[u]] && c[p[u]] < b[u];
  for (char i = a[u] + 1; i < b[u]; ++i)
    if (s[i] == ' ') {
      add(p[u], i);
      return true;
    }
  return false;
}
bool solve2(int u) {
  if (!add(p[u], a[u])) return false;
  for (int i = u + 1; i < n; ++i) {
    bool flag = true;
    for (char j = e; j >= a[i]; --j)
      if (add(p[i], j)) {
        if (j == a[i])
          flag = false;
        else
          return true;
      }
    if (flag) return false;
  }
  return true;
}
bool solve3(int u) {
  if (!add(p[u], b[u])) return false;
  for (int i = u + 1; i < n; ++i) {
    bool flag = true;
    for (char j = 'a'; j <= b[i]; ++j)
      if (add(p[i], j)) {
        if (j == b[i])
          flag = false;
        else
          return true;
      }
    if (flag) return false;
  }
  return true;
}
bool Check() {
  for (int i = 'a'; i <= e; ++i) c[i] = s[i] = ' ';
  for (int i = 0; i < n; ++i) {
    if (a[i] == b[i]) {
      if (!add(p[i], a[i])) return false;
    } else {
      if (solve1(i)) break;
      for (int j = 'a'; j <= e; ++j) {
        _c[j] = c[j];
        _s[j] = s[j];
      }
      if (solve2(i)) break;
      for (int j = 'a'; j <= e; ++j) {
        c[j] = _c[j];
        s[j] = _s[j];
      }
      if (solve3(i)) break;
      return false;
    }
  }
  for (char i = 'a', j = 'a'; i <= e; ++i)
    if (c[i] == ' ') {
      while (s[j] != ' ') ++j;
      c[i] = j;
      s[j] = i;
    }
  return true;
}
void Solve() {
  if (Check()) {
    cout << "YES\n";
    for (int i = 'a'; i <= e; ++i) cout << c[i];
    cout << '\n';
  } else
    cout << "NO\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> T;
  while (T-- > 0) {
    ReadInput();
    Solve();
  }
}
