#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 50;
char str[MAXN];
int s[MAXN], a[MAXN], b[MAXN], p[26];
void solve() {
  int sz;
  scanf("%d", &sz);
  scanf("%s", str);
  int n = strlen(str);
  for (int i = 0; i < n; i++) s[i] = str[i] - 'a';
  scanf("%s", str);
  for (int i = 0; i < n; i++) a[i] = str[i] - 'a';
  scanf("%s", str);
  for (int i = 0; i < n; i++) b[i] = str[i] - 'a';
  memset(p, -1, sizeof p);
  set<int> left;
  for (int i = 0; i < sz; i++) left.insert(i);
  stack<int> st;
  for (int i = 0; i < n; i++) {
    if (p[s[i]] == -1) {
      if (*left.rbegin() < a[i]) {
        bool flag = false;
        while (!st.empty()) {
          int k = st.top();
          st.pop();
          left.insert(p[s[k]]);
          p[s[k]] = -1;
          if (*left.rbegin() > a[k]) {
            int val = *upper_bound(left.begin(), left.end(), a[k]);
            p[s[k]] = val;
            flag = true;
            break;
          }
        }
        if (flag)
          break;
        else {
          printf("NO\n");
          return;
        }
      } else if (left.find(a[i]) != left.end()) {
        p[s[i]] = a[i];
        left.erase(a[i]);
        st.push(i);
      } else {
        int val = *upper_bound(left.begin(), left.end(), a[i]);
        p[s[i]] = val;
        break;
      }
    } else {
      if (p[s[i]] > a[i]) {
        break;
      } else if (p[s[i]] < a[i]) {
        bool flag = false;
        while (!st.empty()) {
          int k = st.top();
          st.pop();
          left.insert(p[s[k]]);
          p[s[k]] = -1;
          if (*left.rbegin() > a[k]) {
            left.insert(p[s[k]]);
            int val = *upper_bound(left.begin(), left.end(), a[k]);
            p[s[k]] = val;
            flag = true;
            break;
          }
        }
        if (flag)
          break;
        else {
          printf("NO\n");
          return;
        }
      }
    }
  }
  left.clear();
  for (int i = 0; i < sz; i++) left.insert(i);
  for (int i = 0; i < sz; i++)
    if (p[i] != -1 && left.find(p[i]) != left.end()) left.erase(p[i]);
  for (int i = 0; i < n; i++) {
    if (p[s[i]] != -1) {
      if (p[s[i]] < b[i]) {
        break;
      } else if (p[s[i]] > b[i]) {
        printf("NO\n");
        return;
      }
    } else {
      p[s[i]] = *left.begin();
      left.erase(p[s[i]]);
      if (p[s[i]] < b[i])
        break;
      else if (p[s[i]] > b[i]) {
        printf("NO\n");
        return;
      }
    }
  }
  left.clear();
  for (int i = 0; i < sz; i++) left.insert(i);
  for (int i = 0; i < sz; i++)
    if (p[i] != -1 && left.find(p[i]) != left.end()) left.erase(p[i]);
  for (int i = 0; i < sz; i++)
    if (p[i] == -1) {
      p[i] = *left.begin();
      left.erase(p[i]);
    }
  printf("YES\n");
  for (int i = 0; i < sz; i++) printf("%c", 'a' + p[i]);
  printf("\n");
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) solve();
}
