#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int x, y;
  y = scanf("%d", &x);
  return x;
}
const int N = 1000 * 1000 + 5;
int a[N], b[N], g[N];
bool mark[26], used[26];
int p[26];
int n, k;
bool solve(int c, bool alim, bool blim) {
  if (c == n) {
    vector<int> unmarked;
    for (int i = 0; i < k; i++)
      if (!mark[i]) unmarked.push_back(i);
    int j = 0;
    for (int i = 0; i < k; i++)
      if (!used[i]) p[unmarked[j++]] = i;
    assert(j == unmarked.size());
    return true;
  }
  if (alim && blim) {
    if (a[c] == b[c]) {
      if (!mark[g[c]]) {
        if (used[a[c]]) return false;
        mark[g[c]] = true;
        used[a[c]] = true;
        p[g[c]] = a[c];
      }
      if (p[g[c]] != a[c]) return false;
      return solve(c + 1, true, true);
    } else {
      if (!mark[g[c]]) {
        for (int i = a[c] + 1; i < b[c]; i++)
          if (!used[i]) {
            mark[g[c]] = true;
            used[i] = true;
            p[g[c]] = i;
            return solve(c + 1, false, false);
          }
        if (!used[a[c]]) {
          bool bmark[26], bused[26];
          memcpy(bmark, mark, k);
          memcpy(bused, used, k);
          mark[g[c]] = true;
          used[a[c]] = true;
          p[g[c]] = a[c];
          if (solve(c + 1, true, false)) return true;
          memcpy(mark, bmark, k);
          memcpy(used, bused, k);
        }
        if (!used[b[c]]) {
          mark[g[c]] = true;
          used[b[c]] = true;
          p[g[c]] = b[c];
          return solve(c + 1, false, true);
        }
        return false;
      } else
        return ((p[g[c]] < a[c] || p[g[c]] > b[c])
                    ? false
                    : solve(c + 1, p[g[c]] == a[c], p[g[c]] == b[c]));
    }
  } else if (alim) {
    if (!mark[g[c]]) {
      for (int i = k - 1; i >= a[c]; i--)
        if (!used[i]) {
          mark[g[c]] = true;
          used[i] = true;
          p[g[c]] = i;
          return solve(c + 1, i == a[c], false);
        }
      return false;
    }
    return (p[g[c]] < a[c] ? false : solve(c + 1, p[g[c]] == a[c], false));
  } else if (blim) {
    if (!mark[g[c]]) {
      for (int i = 0; i <= b[c]; i++)
        if (!used[i]) {
          mark[g[c]] = true;
          used[i] = true;
          p[g[c]] = i;
          return solve(c + 1, false, i == b[c]);
        }
      return false;
    }
    return (p[g[c]] > b[c] ? false : solve(c + 1, false, p[g[c]] == b[c]));
  } else {
    if (!mark[g[c]]) {
      for (int i = 0; i < k; i++)
        if (!used[i]) {
          mark[g[c]] = true;
          used[i] = true;
          p[g[c]] = i;
          return solve(c + 1, false, false);
        }
      return false;
    }
    return solve(c + 1, false, false);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> k;
    string s, sa, sb;
    cin >> s >> sa >> sb;
    n = s.length();
    for (int i = 0; i < n; i++) {
      a[i] = sa[i] - 'a';
      b[i] = sb[i] - 'a';
    }
    for (int i = 0; i < n; i++) g[i] = s[i] - 'a';
    fill(mark, mark + 26, false);
    fill(used, used + 26, false);
    if (!solve(0, true, true))
      cout << "NO\n";
    else {
      cout << "YES\n";
      for (int i = 0; i < k; i++) cout << char('a' + p[i]);
      cout << '\n';
    }
  }
  return 0;
}
