#include <bits/stdc++.h>
using namespace std;
const int infi = 1e9 + 7;
const long long infl = (long long)1e18 + (long long)7;
string s, a, b;
int flag_ans;
char ans[1000500];
int used[26];
char to[26];
int le(int flag, char a, char b) { return flag || a <= b; }
int lt(int flag, char a, char b) { return flag || a < b; }
int n, k;
inline void solve(int i, int flag1, int flag2) {
  if (i == n) {
    flag_ans = 1;
    return;
  }
  if (to[s[i]] != -1) {
    ans[i] = to[s[i]];
    if (!le(flag1, a[i], ans[i]) || !le(flag2, ans[i], b[i])) {
      return;
    }
    solve(i + 1, lt(flag1, a[i], ans[i]), lt(flag2, ans[i], b[i]));
    return;
  }
  int c;
  int q = a[i], w = b[i];
  if (flag1) q = 0;
  if (flag2) w = k - 1;
  for (c = q + 1; c < w && used[c]; ++c)
    ;
  if (c < w) {
    used[c] = 1;
    to[s[i]] = c;
    solve(i, flag1, flag2);
    used[c] = 0;
    to[s[i]] = -1;
    return;
  }
  if (used[q] && used[w]) return;
  if (used[q]) {
    c = w;
    used[c] = 1;
    to[s[i]] = c;
    solve(i, flag1, flag2);
    used[c] = 0;
    to[s[i]] = -1;
    return;
  }
  if (used[w]) {
    c = q;
    used[c] = 1;
    to[s[i]] = c;
    solve(i, flag1, flag2);
    used[c] = 0;
    to[s[i]] = -1;
    return;
  }
  if (flag2) {
    c = w;
    used[c] = 1;
    to[s[i]] = c;
    solve(i, flag1, flag2);
    used[c] = 0;
    to[s[i]] = -1;
    return;
  }
  c = q;
  used[c] = 1;
  to[s[i]] = c;
  solve(i, flag1, flag2);
  used[c] = 0;
  to[s[i]] = -1;
  if (flag_ans || q == w) {
    return;
  }
  c = w;
  used[c] = 1;
  to[s[i]] = c;
  solve(i, flag1, flag2);
  used[c] = 0;
  to[s[i]] = -1;
  return;
}
void get_ans(int n) {
  for (int i = 0; i < (n); ++i) to[s[i]] = ans[i], used[ans[i]] = 1;
  vector<int> tmp;
  for (int i = 0; i < (k); ++i)
    if (!used[i]) tmp.emplace_back(i);
  for (int i = 0; i < (k); ++i)
    if (to[i] == -1) {
      to[i] = tmp.back();
      tmp.pop_back();
    }
}
int32_t main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> k;
    cin >> s >> a >> b;
    n = s.size();
    for (int i = 0; i < (n); ++i) s[i] -= 'a', a[i] -= 'a', b[i] -= 'a';
    flag_ans = 0;
    for (int i = 0; i < (k); ++i) {
      used[i] = 0;
      to[i] = -1;
    }
    solve(0, 0, 0);
    string res;
    if (flag_ans) {
      get_ans(n);
      cout << "YES\n";
      for (int i = 0; i < (k); ++i) res += (to[i] + 'a');
      cout << res << '\n';
    } else {
      cout << "NO\n";
    }
  }
  return 0;
}
