#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long N = 1e9 + 7, M = 20, N2 = 1234567891;
int x, y, z, i, j, n, m, k, l, r, t,
    ma = 0, ans, x2, y2, x3, y3, f, kol, mi, fl, a[1101000], b[1101000],
    b2[1101000], d[1101000], dl[1101000], dr[1101000], dp[1101000], p[1101000];
string s, s2, s3;
vector<int> v[410000], v2, v3;
bool ch() {
  for (int i = 1; i <= k; i++)
    if (dp[i] > k || dp[i] < 1) return 0;
  for (int i = 1; i <= k; i++)
    for (int j = 1; j <= k; j++)
      if (dp[i] == dp[j] && i != j) return 0;
  for (int i = 1; i <= n; i++) {
    if (dp[a[i]] < dl[i]) return 0;
    if (dp[a[i]] > dl[i]) break;
  }
  for (int i = 1; i <= n; i++) {
    if (dp[a[i]] > dr[i]) return 0;
    if (dp[a[i]] < dr[i]) break;
  }
  return 1;
}
void spred(int kr) {
  for (int i = 1; i <= k; i++) p[i] = 0;
  bool f = 0;
  for (int i = 1; i <= n; i++) {
    if (!f) p[a[i]] = 1;
    if (dp[a[i]] > dl[i]) f = 1;
    if (f && !p[a[i]]) dp[a[i]] = 1;
    if (!f && dp[a[i]] < dl[i]) break;
  }
  for (int i = 1; i <= k; i++)
    if (!p[i]) dp[i] = 1;
  for (int i = 1; i <= k; i++) p[i] = 0;
  for (int i = 0; i < k; i++) {
    int x = v2[i];
    bool f = 0;
    for (int j = dp[x]; j <= k; j++) {
      if (!p[j]) {
        dp[x] = j;
        f = 1;
        p[j] = 1;
        break;
      }
    }
  }
  if (kr == 26) return;
  spred(kr + 1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    cin >> k >> s >> s2 >> s3;
    n = (int)s.size();
    for (i = 0; i < n; i++) {
      a[i + 1] = s[i] - 'a' + 1;
    }
    for (i = 0; i < n; i++) {
      dl[i + 1] = s2[i] - 'a' + 1;
    }
    for (i = 0; i < n; i++) {
      dr[i + 1] = s3[i] - 'a' + 1;
    }
    for (i = 1; i <= k; i++) dp[i] = 0, b[i] = 0, b2[i] = 0, p[i] = 0;
    f = 0;
    v2 = v3;
    fl = 0;
    l = 0;
    r = 1e9;
    t = 0;
    for (i = 1; i <= n; i++) {
      if (!p[a[i]]) {
        p[a[i]] = 1;
        v2.push_back(a[i]);
        dp[a[i]] = dl[i];
        x = dp[a[i]];
        for (j = 1; j <= x; j++) {
          b[j]++;
          if (b[j] > k - j + 1) r = min(r, i);
        }
        if (i < r && x != k && b[x + 1] != k - x) t = max(t, i);
      } else if (!b2[a[i]] && dl[i] != dp[a[i]]) {
        f = 1;
        b2[a[i]] = i;
        if (dl[i] > dp[a[i]]) {
          r = min(r, i);
        }
      }
    }
    for (i = 1; i <= k; i++) {
      if (!p[i]) {
        dp[i] = 1;
        v2.push_back(i);
      }
    }
    for (i = 1; i <= k; i++) b2[i] = dp[i];
    spred(1);
    if (ch()) {
      cout << "YES\n";
      for (i = 1; i <= k; i++) {
        cout << (char)(dp[i] + 'a' - 1);
      }
      cout << "\n";
      continue;
    }
    for (i = 1; i <= k; i++) dp[i] = b2[i];
    dp[a[t]]++;
    spred(1);
    if (!ch()) {
      cout << "NO\n";
      continue;
    }
    cout << "YES\n";
    for (i = 1; i <= k; i++) {
      cout << (char)(dp[i] + 'a' - 1);
    }
    cout << "\n";
  }
}
