#include <bits/stdc++.h>
using namespace std;
string a, b, s;
int cases;
string getres(int k, int *from, int *to) {
  string res;
  for (int i = 0; i < k; i++) {
    if (to[i] == -1) {
      for (int j = 0; j < k; j++) {
        if (from[j] == -1) {
          from[j] = i;
          to[i] = j;
          break;
        }
      }
    }
    res += (char)(to[i] + 'a');
  }
  return res;
}
string solve(int targeti, int k, string &s, string &a, string &b, bool maximize,
             int *from, int *to) {
  for (int i = targeti + 1; i < s.size(); i++) {
    int ss = s[i] - 'a', aa = a[i] - 'a', bb = b[i] - 'a';
    if (to[ss] != -1) {
      if (maximize && to[ss] < aa) return "";
      if (!maximize && to[ss] > bb) return "";
      if (maximize && to[ss] > aa) return getres(k, from, to);
      if (!maximize && to[ss] < bb) return getres(k, from, to);
    } else {
      if (maximize) {
        for (int j = k - 1; j > aa; j--) {
          if (from[j] == -1) {
            from[j] = ss;
            to[ss] = j;
            return getres(k, from, to);
          }
        }
        if (from[aa] == -1) {
          from[aa] = ss;
          to[ss] = aa;
        } else
          return "";
      } else {
        for (int j = 0; j < bb; j++) {
          if (from[j] == -1) {
            from[j] = ss;
            to[ss] = j;
            return getres(k, from, to);
          }
        }
        if (from[bb] == -1) {
          from[bb] = ss;
          to[ss] = bb;
        } else
          return "";
      }
    }
  }
  return getres(k, from, to);
}
string solve(int k, string &s, string &a, string &b) {
  int from[k];
  int to[k];
  memset(from, -1, sizeof from);
  memset(to, -1, sizeof to);
  for (int i = 0; i < s.size(); i++) {
    int aa = a[i] - 'a', bb = b[i] - 'a', ss = s[i] - 'a';
    if (to[ss] != -1) {
      if (to[ss] < aa || to[ss] > bb) {
        return "";
      }
      if (aa < bb) {
        if (to[ss] == aa) return solve(i, k, s, a, b, true, from, to);
        if (to[ss] == bb) return solve(i, k, s, a, b, false, from, to);
        assert(to[ss] > aa && to[ss] < bb);
        return getres(k, from, to);
      }
    } else {
      for (int j = aa + 1; j <= bb - 1; j++) {
        if (from[j] == -1) {
          to[ss] = j;
          from[j] = ss;
          return getres(k, from, to);
        }
      }
      if (aa == bb) {
        if (from[aa] != -1) {
          return "";
        }
        to[ss] = aa;
        from[aa] = ss;
      } else {
        int fromt[k], tot[k];
        if (from[aa] == -1) {
          memcpy(fromt, from, sizeof fromt);
          memcpy(tot, to, sizeof tot);
          tot[ss] = aa;
          fromt[aa] = ss;
          string r = solve(i, k, s, a, b, true, fromt, tot);
          if (r.size()) return r;
        }
        if (from[bb] == -1) {
          memcpy(fromt, from, sizeof fromt);
          memcpy(tot, to, sizeof tot);
          tot[ss] = bb;
          fromt[bb] = ss;
          string r = solve(i, k, s, a, b, false, fromt, tot);
          if (r.size()) return r;
        }
        return "";
      }
    }
  }
  return getres(k, from, to);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> cases;
  for (int i = 0; i < cases; i++) {
    int size;
    cin >> size;
    cin >> s >> a >> b;
    string sol = solve(size, s, a, b);
    if (sol.size()) {
      cout << "YES\n";
      cout << sol << "\n";
    } else
      cout << "NO\n";
  }
}
