#include <bits/stdc++.h>
using namespace std;
int t, k;
string s, a, b;
map<char, char> p;
set<char> l;
char getLarger(char c) {
  if (l.lower_bound(c) == l.end()) return 'z' + 5;
  return *l.lower_bound(c);
}
char getSmaller(char c) {
  if (l.upper_bound(c) == l.begin()) return 'z' + 5;
  return *(--l.upper_bound(c));
}
bool isOk(char c) { return c != 'z' + 5; }
bool tryLow() {
  p.clear();
  l.clear();
  for (int i = 0; i < k; i++) l.insert((char)('a' + i));
  int i = 0;
  while (i < s.size() && a[i] == b[i]) {
    if (p[s[i]] == 0 || p[s[i]] == a[i]) {
      if (p[s[i]] == 0) {
        char c = getLarger(a[i]);
        if (c != a[i]) return false;
        p[s[i]] = c;
        l.erase(c);
      }
    } else
      return false;
    i++;
  }
  bool ga = false, sb = false;
  while ((!ga || !sb) && i < s.size()) {
    if (p[s[i]] == 0) {
      char c = 'z' + 5;
      if (ga)
        c = getLarger('a');
      else
        c = getLarger(a[i]);
      if (!ga && isOk(getLarger(c + 1)) && a[i] < getLarger(c + 1) &&
          (sb || getLarger(c + 1) < b[i]))
        c = getLarger(c + 1);
      if (!isOk(c)) return false;
      p[s[i]] = c;
      l.erase(c);
    }
    if (!ga && a[i] > p[s[i]] || !sb && b[i] < p[s[i]]) return false;
    ga = ga || p[s[i]] > a[i];
    sb = sb || p[s[i]] < b[i];
    i++;
  }
  return true;
}
bool tryHigh() {
  p.clear();
  l.clear();
  for (int i = 0; i < k; i++) l.insert((char)('a' + i));
  int i = 0;
  while (i < s.size() && a[i] == b[i]) {
    if (p[s[i]] == 0 || p[s[i]] == a[i]) {
      if (p[s[i]] == 0) {
        char c = getLarger(a[i]);
        if (c != a[i]) return false;
        p[s[i]] = c;
        l.erase(c);
      }
    } else
      return false;
    i++;
  }
  bool ga = false, sb = false;
  while ((!ga || !sb) && i < s.size()) {
    if (p[s[i]] == 0) {
      char c = 'z' + 5;
      if (sb)
        c = getSmaller('z');
      else
        c = getSmaller(b[i]);
      if (!sb && isOk(getSmaller(c - 1)) && (ga || a[i] < getSmaller(c - 1)) &&
          getSmaller(c - 1) < b[i])
        c = getSmaller(c - 1);
      if (!isOk(c)) return false;
      p[s[i]] = c;
      l.erase(c);
    }
    if (!ga && a[i] > p[s[i]] || !sb && b[i] < p[s[i]]) return false;
    ga = ga || p[s[i]] > a[i];
    sb = sb || p[s[i]] < b[i];
    i++;
  }
  return true;
}
void fill() {
  for (int i = 0; i < k; i++)
    if (p['a' + i] == 0) {
      char c = getLarger('a');
      p['a' + i] = c;
      l.erase(c);
    }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> t;
  while (t--) {
    cin >> k;
    cin >> s >> a >> b;
    if (tryHigh() || tryLow()) {
      fill();
      cout << "YES\n";
      for (int i = 0; i < k; i++) cout << p['a' + i];
      cout << "\n";
    } else
      cout << "NO\n";
  }
}
