#include <bits/stdc++.h>
using namespace std;
template <typename T>
void setmax(T& x, T y) {
  x = max(x, y);
}
template <typename T>
void setmin(T& x, T y) {
  x = min(x, y);
}
const double PI = acos(-1.0);
const long long INF = 1e9 + 47;
const long long LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int k;
bool goA(vector<int>& s, vector<int>& a, vector<int>& to, vector<int>& rev,
         int pos) {
  int n = (int)((s).size());
  for (int i = (pos); i < (n); ++i) {
    for (int j = (a[i] + 1); j < (k); ++j) {
      if (to[s[i]] == -1 && rev[j] == -1) {
        to[s[i]] = j;
        rev[j] = s[i];
      }
      if (to[s[i]] == j && rev[j] == s[i]) return true;
    }
    if (to[s[i]] == -1 && rev[a[i]] == -1) {
      to[s[i]] = a[i];
      rev[a[i]] = s[i];
    }
    if (to[s[i]] != a[i] || rev[a[i]] != s[i]) return false;
  }
  return true;
}
bool goB(vector<int>& s, vector<int>& a, vector<int>& to, vector<int>& rev,
         int pos) {
  int n = (int)((s).size());
  for (int i = (pos); i < (n); ++i) {
    for (int j = (0); j < (a[i]); ++j) {
      if (to[s[i]] == -1 && rev[j] == -1) {
        to[s[i]] = j;
        rev[j] = s[i];
      }
      if (to[s[i]] == j && rev[j] == s[i]) return true;
    }
    if (to[s[i]] == -1 && rev[a[i]] == -1) {
      to[s[i]] = a[i];
      rev[a[i]] = s[i];
    }
    if (to[s[i]] != a[i] || rev[a[i]] != s[i]) return false;
  }
  return true;
}
vector<int> GO(string& a) {
  vector<int> res((int)((a).size()));
  for (int i = (0); i < ((int)((res).size())); ++i) res[i] = a[i] - 'a';
  return res;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> k;
    string S, A, B;
    cin >> S >> A >> B;
    vector<int> s = GO(S);
    vector<int> a = GO(A);
    vector<int> b = GO(B);
    int n = (int)((a).size());
    vector<int> to(k, -1);
    vector<int> rev(k, -1);
    bool ok = true;
    for (int i = (0); i < (n); ++i) {
      bool fnd = false;
      for (int j = (a[i] + 1); j < (b[i]); ++j) {
        if (to[s[i]] == -1 && rev[j] == -1) {
          to[s[i]] = j;
          rev[j] = s[i];
        }
        if (to[s[i]] == j && rev[j] == s[i]) {
          fnd = true;
          break;
        }
      }
      if (fnd) break;
      if (a[i] == b[i]) {
        if (to[s[i]] == a[i]) continue;
        if (to[s[i]] != -1 || rev[a[i]] != -1) {
          ok = false;
          break;
        }
        to[s[i]] = a[i];
        rev[a[i]] = s[i];
        continue;
      }
      auto huj = to, HUJ = rev;
      if ((to[s[i]] == -1 && rev[a[i]] == -1) ||
          (to[s[i]] == a[i] && rev[a[i]] == s[i])) {
        to[s[i]] = a[i];
        rev[a[i]] = s[i];
        if (goA(s, a, to, rev, i + 1)) break;
      }
      to = huj;
      rev = HUJ;
      if ((to[s[i]] == -1 && rev[b[i]] == -1) ||
          (to[s[i]] == b[i] && rev[b[i]] == s[i])) {
        to[s[i]] = b[i];
        rev[b[i]] = s[i];
        if (goB(s, b, to, rev, i + 1)) break;
      }
      ok = false;
      break;
    }
    if (!ok) {
      cout << "NO\n";
      continue;
    }
    cout << "YES\n";
    vector<int> U1, U2;
    for (int i = (0); i < (k); ++i)
      if (to[i] == -1) U1.push_back(i);
    for (int i = (0); i < (k); ++i)
      if (rev[i] == -1) U2.push_back(i);
    assert((int)((U1).size()) == (int)((U2).size()));
    for (int i = (0); i < ((int)((U1).size())); ++i) {
      to[U1[i]] = U2[i];
      rev[U2[i]] = U1[i];
    }
    for (int i = (0); i < (k); ++i) cout << (char)('a' + to[i]);
    cout << '\n';
  }
  cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
  return 0;
}
