#include <bits/stdc++.h>
using namespace std;
const double PI = 2 * acos(0.0);
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
template <class T>
ostream &operator<<(ostream &out, vector<T> &a) {
  out << "(";
  for (auto x : a) out << x << " ";
  return out << ")";
}
void smain();
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << setprecision(12) << fixed;
  smain();
}
int k;
string s, a, b;
int n;
const int L = 27;
bool glob_ok;
void build_str(vector<int> mark, vector<char> used) {
  assert(!glob_ok);
  cout << "YES\n";
  glob_ok = 1;
  vector<int> fre;
  for (int i = 0; i < k; ++i)
    if (!used[i]) fre.push_back(i);
  string res = "";
  for (int i = 0; i < k; ++i) {
    if (mark[i] == -1) {
      mark[i] = fre.back();
      fre.pop_back();
    }
    res += char(mark[i] + 'a');
  }
  cout << res << "\n";
}
void go_less(vector<int> mark, vector<char> used, int ind) {
  for (int i = ind; i < n; ++i) {
    int l = a[i] - 'a';
    int cur = s[i] - 'a';
    if (mark[cur] != -1) {
      if (mark[cur] < l) return;
      if (mark[cur] == l) continue;
      build_str(mark, used);
      return;
    }
    for (int j = l + 1; j < k; ++j) {
      if (!used[j]) {
        used[j] = 1;
        mark[cur] = j;
        build_str(mark, used);
        return;
      }
    }
    if (used[l]) return;
    mark[cur] = l;
    used[l] = 1;
  }
  build_str(mark, used);
}
void go_more(vector<int> mark, vector<char> used, int ind) {
  for (int i = ind; i < n; ++i) {
    int r = b[i] - 'a';
    int cur = s[i] - 'a';
    if (mark[cur] != -1) {
      if (mark[cur] > r) return;
      if (mark[cur] == r) continue;
      build_str(mark, used);
      return;
    }
    for (int j = r - 1; j >= 0; --j) {
      if (!used[j]) {
        used[j] = 1;
        mark[cur] = j;
        build_str(mark, used);
        return;
      }
    }
    if (used[r]) return;
    mark[cur] = r;
    used[r] = 1;
  }
  build_str(mark, used);
}
void smain() {
  int t;
  cin >> t;
  while (t--) {
    cin >> k >> s >> a >> b;
    vector<int> mark(k, -1);
    vector<char> used(k, 0);
    glob_ok = false;
    n = s.size();
    bool eq = 1;
    for (int i = 0; i < n; ++i) {
      int cur = s[i] - 'a';
      int l = a[i] - 'a';
      int r = b[i] - 'a';
      if (l == r) {
        if (mark[cur] != -1) {
          if (mark[cur] != l) {
            eq = false;
            break;
          }
        } else {
          if (used[l]) {
            eq = false;
            break;
          }
          mark[cur] = l;
          used[l] = 1;
        }
        continue;
      }
      if (mark[cur] != -1) {
        if (mark[cur] < l || mark[cur] > r) {
          eq = false;
        } else {
          if (mark[cur] == l) {
            eq = false;
            go_less(mark, used, i + 1);
          } else if (mark[cur] == r) {
            eq = false;
            go_more(mark, used, i + 1);
          } else {
          }
        }
      } else {
        vector<int> fre;
        bool found = 0;
        for (int j = l; j <= r; ++j) {
          if (!used[j]) {
            fre.push_back(j);
            if (j != l && j != r) {
              mark[cur] = j;
              used[j] = 1;
              found = 1;
              break;
            }
          }
        }
        if (found) break;
        eq = false;
        if (fre.size() == 0) {
          break;
        } else if (fre.size() == 1) {
          mark[cur] = fre[0];
          used[fre[0]] = 1;
          if (l == mark[cur]) go_less(mark, used, i + 1);
          if (r == mark[cur]) go_more(mark, used, i + 1);
          break;
        } else if (fre.size() == 2) {
          mark[cur] = l;
          used[l] = 1;
          go_less(mark, used, i + 1);
          if (!glob_ok) {
            mark[cur] = r;
            used[l] = 0;
            used[r] = 1;
            go_more(mark, used, i + 1);
          }
        }
      }
      break;
    }
    if (glob_ok) {
      continue;
    }
    if (!eq) {
      cout << "NO\n";
    } else {
      build_str(mark, used);
    }
  }
}
