#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > adj;
char subst[26];
bool was_to[26];
bool add_subst(char from, char to) {
  if ((subst[from - 'a'] == -1 && !was_to[to - 'a']) ||
      subst[from - 'a'] == to) {
    subst[from - 'a'] = to;
    was_to[to - 'a'] = true;
    return true;
  } else {
    return false;
  }
}
char subst_copy[26];
bool was_to_copy[26];
char tmp[1000007];
void solve() {
  int k;
  string s, a, b;
  scanf("%d\n", &k);
  scanf("%s", tmp);
  int counter = strlen(tmp);
  for (int i = 0; i < counter; i++) {
    s += tmp[i];
  }
  scanf("%s", tmp);
  counter = strlen(tmp);
  for (int i = 0; i < counter; i++) {
    a += tmp[i];
  }
  scanf("%s", tmp);
  counter = strlen(tmp);
  for (int i = 0; i < counter; i++) {
    b += tmp[i];
  }
  for (int i = 0; i < k; i++) {
    subst[i] = -1;
    was_to[i] = false;
  }
  int state = 0;
  for (int i = 0; i < s.size(); i++) {
    if (a[i] == b[i]) {
      if (!add_subst(s[i], a[i])) {
        printf("NO\n");
        return;
      }
      continue;
    }
    for (char ch = a[i] + 1; ch < b[i]; ch++) {
      if (add_subst(s[i], ch)) {
        goto fo;
      }
    }
    memcpy(subst_copy, subst, sizeof(subst));
    memcpy(was_to_copy, was_to, sizeof(was_to));
    if (add_subst(s[i], a[i])) {
      bool flag = true;
      for (int j = i + 1; j < s.size(); j++) {
        for (char ch = a[j] + 1; ch < k + 'a'; ch++) {
          if (add_subst(s[j], ch)) {
            goto fo;
          }
        }
        flag = add_subst(s[j], a[j]);
        if (!flag) {
          break;
        }
      }
      if (flag) {
        goto fo;
      }
    }
    memcpy(subst, subst_copy, sizeof(subst));
    memcpy(was_to, was_to_copy, sizeof(was_to));
    if (add_subst(s[i], b[i])) {
      bool flag = true;
      for (int j = i + 1; j < s.size(); j++) {
        for (char ch = 'a'; ch < b[j]; ch++) {
          if (add_subst(s[j], ch)) {
            goto fo;
          }
        }
        flag &= add_subst(s[j], b[j]);
        if (!flag) {
          break;
        }
      }
      if (flag) {
        goto fo;
      }
    }
    printf("NO\n");
    return;
  }
fo:
  printf("YES\n");
  for (int i = 0; i < k; i++) {
    if (subst[i] == -1) {
      for (int j = 0; j < k; j++) {
        if (!was_to[j]) {
          was_to[j] = true;
          subst[i] = 'a' + j;
          break;
        }
      }
    }
    putc(subst[i], stdout);
  }
  putc('\n', stdout);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  scanf("%d", &t);
  for (int i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
