#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 42;
string get_options(const string& P, int l, int r) {
  string res;
  for (int i = l; i <= r; ++i) {
    if (P.find(i) == string::npos) {
      res.push_back(i);
    }
  }
  return res;
}
string fill_somehow(string P) {
  int k = P.size(), j = 0;
  for (int i = 0; i < k; ++i) {
    if (P[i] != '*') {
      continue;
    }
    while (P.find(j) != string::npos) {
      ++j;
    }
    P[i] = j;
  }
  return P;
}
string fill_less(string P, const string& S) {
  int n = S.size(), j = 0;
  for (int i = 0; i < n; ++i) {
    if (P[S[i]] != '*') {
      continue;
    }
    while (P.find(j) != string::npos) {
      ++j;
    }
    P[S[i]] = j;
  }
  return P;
}
string fill_greater(string P, const string& S) {
  int n = S.size(), j = int(P.size()) - 1;
  for (int i = 0; i < n; ++i) {
    if (P[S[i]] != '*') {
      continue;
    }
    while (P.find(j) != string::npos) {
      --j;
    }
    P[S[i]] = j;
  }
  return P;
}
bool check(const string& P, const string& S, const string& A, const string& B) {
  string S_;
  for (char el : S) {
    S_.push_back(P[el]);
  }
  return A <= S_ && S_ <= B;
}
string f(string S) {
  for (int i = 0; i < S.size(); ++i) {
    if (S[i] != '*') {
      S[i] += 'a';
    }
  }
  return S;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  for (int _ = 0; _ < t; ++_) {
    int k;
    cin >> k;
    string P;
    for (int i = 0; i < k; ++i) P.push_back('*');
    string S, A, B;
    cin >> S >> A >> B;
    int n = S.size();
    for (int i = 0; i < n; ++i) {
      S[i] -= 'a';
      A[i] -= 'a';
      B[i] -= 'a';
    }
    bool f1 = false, f2 = false;
    int i;
    for (i = 0; i < n; ++i) {
      if (P[S[i]] == '*') {
        string options = get_options(P, min(int(A[i]), (k - 1) * int(!f1)),
                                     max(int(B[i]), (k - 1) * f2));
        if (options.size() == 0) {
          i = n;
          break;
        } else if (options.size() == 1) {
          P[S[i]] = options.front();
        } else {
          break;
        }
      }
      if (P[S[i]] > A[i]) {
        f1 = true;
      }
      if (P[S[i]] < B[i]) {
        f2 = true;
      }
    }
    if (i == n) {
      P = fill_somehow(P);
      if (check(P, S, A, B)) {
        cout << "YES\n";
        cout << f(P) << "\n";
      } else {
        cout << "NO\n";
      }
      continue;
    }
    bool OK = false;
    for (int el : get_options(P, min(int(A[i]), (k - 1) * int(!f1)),
                              max(int(B[i]), (k - 1) * f2))) {
      P[S[i]] = el;
      string P_;
      P_ = fill_less(P, S.substr(i + 1, n - i - 1));
      if (check(P_, S, A, B)) {
        P = P_;
        OK = true;
        break;
      }
      P_ = fill_greater(P, S.substr(i + 1, n - i - 1));
      if (check(P_, S, A, B)) {
        P = P_;
        OK = true;
        break;
      }
      P[S[i]] = '*';
    }
    if (!OK) {
      cout << "NO\n";
    } else {
      cout << "YES\n";
      cout << f(fill_somehow(P)) << "\n";
    }
  }
  cerr << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
  return 0;
}
