#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 69;
int a[N], b[N], s[N], to[30], used[30], n, len, tmp_to[30], tmp_used[30], test,
    last;
void print(int val) {
  if (!val) {
    cout << "NO\n";
    return;
  }
  cout << "YES\n";
  for (int i = 0; i < n; i++) {
    if (to[i] != -1)
      cout << char(to[i] + 'a');
    else {
      for (int j = 0; j < n; j++)
        if (!used[j]) {
          used[j] = 1;
          cout << char(j + 'a');
          break;
        }
    }
  }
  cout << '\n';
}
void init() {
  for (int i = 0; i < n; i++) {
    used[i] = tmp_used[i];
    to[i] = tmp_to[i];
  }
}
int greater_lex() {
  memset(tmp_used, 0, sizeof tmp_used);
  memset(tmp_to, -1, sizeof tmp_to);
  for (int i = 0; i < n; i++) {
    tmp_used[i] = used[i];
    tmp_to[i] = to[i];
  }
  if (tmp_to[s[last]] != a[last]) {
    if (tmp_to[s[last]] != -1 || tmp_used[a[last]]) return 0;
    tmp_to[s[last]] = a[last];
    tmp_used[a[last]] = 1;
  }
  for (int i = last + 1; i <= len; i++) {
    if (tmp_to[s[i]] != -1) {
      if (tmp_to[s[i]] < a[i]) return 0;
      if (tmp_to[s[i]] > a[i]) {
        init();
        return 1;
      }
      continue;
    }
    for (int j = a[i] + 1; j < n; j++) {
      if (!tmp_used[j]) {
        tmp_to[s[i]] = j;
        tmp_used[j] = 1;
        init();
        return 1;
      }
    }
    if (tmp_used[a[i]]) return 0;
    tmp_to[s[i]] = a[i];
    tmp_used[a[i]] = 1;
  }
  init();
  return 1;
}
int less_lex() {
  memset(tmp_used, 0, sizeof tmp_used);
  memset(tmp_to, -1, sizeof tmp_to);
  for (int i = 0; i < n; i++) {
    tmp_used[i] = used[i];
    tmp_to[i] = to[i];
  }
  if (tmp_to[s[last]] != b[last]) {
    if (tmp_to[s[last]] != -1 || tmp_used[b[last]]) return 0;
    tmp_to[s[last]] = b[last];
    tmp_used[b[last]] = 1;
  }
  for (int i = last + 1; i <= len; i++) {
    if (tmp_to[s[i]] != -1) {
      if (tmp_to[s[i]] > b[i]) return 0;
      if (tmp_to[s[i]] < b[i]) {
        init();
        return 1;
      }
      continue;
    }
    for (int j = 0; j < b[i]; j++) {
      if (!tmp_used[j]) {
        tmp_to[s[i]] = j;
        tmp_used[j] = 1;
        init();
        return 1;
      }
    }
    if (tmp_used[b[i]]) return 0;
    tmp_to[s[i]] = b[i];
    tmp_used[b[i]] = 1;
  }
  init();
  return 1;
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> test;
  while (test--) {
    string s1, s2, s3;
    cin >> n >> s1 >> s2 >> s3;
    len = s1.length();
    for (int i = 0; i < len; i++) s[i + 1] = s1[i] - 'a';
    for (int i = 0; i < len; i++) a[i + 1] = s2[i] - 'a';
    for (int i = 0; i < len; i++) b[i + 1] = s3[i] - 'a';
    memset(used, 0, sizeof used);
    memset(to, -1, sizeof to);
    last = len + 1;
    int check = 1;
    for (int i = 1; i <= len; i++) {
      if (a[i] != b[i]) {
        last = i;
        break;
      }
      if (to[s[i]] == a[i]) continue;
      if (to[s[i]] == -1 && !used[a[i]]) {
        to[s[i]] = a[i];
        used[a[i]] = 1;
      } else {
        check = 0;
        break;
      }
    }
    if (!check) {
      print(0);
      continue;
    }
    if (last == len + 1) {
      print(1);
      continue;
    }
    if (a[last] < to[s[last]] && to[s[last]] < b[last]) {
      print(1);
      continue;
    }
    check = 0;
    for (int i = a[last] + 1; i <= b[last] - 1; i++) {
      if (to[s[last]] == -1 && !used[i]) {
        to[s[last]] = i;
        used[i] = 1;
        check = 1;
        break;
      }
    }
    if (check) {
      print(1);
      continue;
    }
    if (greater_lex()) {
      print(1);
      continue;
    }
    if (less_lex()) {
      print(1);
      continue;
    }
    print(0);
  }
}
