#include <bits/stdc++.h>
using namespace std;
bool build(string s, string t, bool comp, set<char> &cur, map<char, char> &per,
           int j, char k) {
  set<char> c = cur;
  map<char, char> p = per;
  if (p.find(s[j]) == p.end()) {
    for (auto i : c) {
      if ((comp && i < k && i > t[j]) || (!comp && i > k && i < t[j])) {
        p[s[j]] = i;
        c.erase(i);
        break;
      }
    }
    if (p.find(s[j]) == p.end()) {
      if (c.find(t[j]) == c.end()) return false;
      p[s[j]] = t[j];
      c.erase(t[j]);
    }
  } else if ((comp && p[s[j]] >= k) || (!comp && p[s[j]] <= k))
    return false;
  bool res = true;
  int n = s.length();
  for (int i = 0; i < n; i++) {
    char u = s[i];
    if (p.find(u) != p.end()) {
      if ((comp && p[u] < t[i]) || (!comp && p[u] > t[i])) {
        res = false;
        break;
      }
      if (p[u] != t[i]) break;
    } else {
      for (auto j : c)
        if ((comp && j > t[i]) || (!comp && j < t[i])) {
          p[u] = j;
          c.erase(j);
          break;
        }
      if (p.find(u) != p.end()) break;
      if (c.find(t[i]) == c.end()) {
        res = false;
        break;
      }
      p[u] = t[i];
      c.erase(t[i]);
    }
  }
  if (res) {
    cur = c;
    per = p;
  }
  return res;
}
void finish(map<char, char> &per, set<char> &cur, int k) {
  char sa = 'a';
  assert(cur.size() + per.size() == k);
  for (int i = 0; i < k; i++) {
    if (per.find(sa) == per.end()) {
      per[sa] = *cur.begin();
      cur.erase(*cur.begin());
    }
    sa++;
  }
}
const int maxn = 1e6 + 5;
char in[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  scanf("%d", &t);
  while (t--) {
    int k;
    scanf("%d", &k);
    string s, a, b;
    scanf("%s", &in);
    s = in;
    scanf("%s", &in);
    a = in;
    scanf("%s", &in);
    b = in;
    int n = s.length();
    char sa = 'a';
    map<char, char> per;
    set<char> cur;
    for (int i = 0; i < k; i++) cur.insert(sa++);
    if (n == 1) {
      printf("YES\n");
      per[s[0]] = a[0];
      cur.erase(a[0]);
      finish(per, cur, k);
      sa = 'a';
      for (int i = 0; i < k; i++) {
        putchar(per[sa++]);
      }
      printf("\n");
      continue;
    }
    bool ok = true;
    int j = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == b[i]) {
        if (per.find(s[i]) == per.end()) {
          if (cur.find(a[i]) == cur.end()) {
            ok = false;
            break;
          }
          per[s[i]] = a[i];
          cur.erase(a[i]);
        } else if (per[s[i]] != a[i]) {
          ok = false;
          break;
        }
        j++;
      } else {
        break;
      }
    }
    assert(cur.size() + per.size() == k);
    if (j == n) {
      printf("YES\n");
      finish(per, cur, k);
      sa = 'a';
      for (int i = 0; i < k; i++) {
        putchar(per[sa++]);
      }
      printf("\n");
      continue;
    }
    if (!ok) {
      printf("NO\n");
      continue;
    }
    ok = build(s, a, true, cur, per, j, b[j]);
    if (!ok) ok = build(s, b, false, cur, per, j, a[j]);
    if (ok) {
      finish(per, cur, k);
      printf("YES\n");
      sa = 'a';
      for (int i = 0; i < k; i++) {
        putchar(per[sa++]);
      }
      printf("\n");
    } else {
      printf("NO\n");
    }
  }
  return 0;
}
