#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.141592653589793238462643;
int t;
string s, a, b;
int k;
int ch[300];
bool was[300];
int n;
void get(int pos) {
  for (int j = 0; j < (k); j++) {
    if (!ch[j + 'a']) {
      for (int p = 0; p < (k); p++) {
        if (!was[p + 'a']) {
          ch[j + 'a'] = p + 'a';
          was[p + 'a'] = 1;
          break;
        }
      }
    }
  }
  cout << "YES\n";
  for (int j = 0; j < (k); j++) {
    cout << (char)ch[j + 'a'];
  }
  cout << endl;
}
void go() {
  for (int i = 'a'; i <= 'z'; i++) ch[i] = was[i] = 0;
  n = ((int)(s).size());
  int i = 0;
  while (i < n && a[i] == b[i]) {
    if (!was[a[i]] && !ch[s[i]]) {
      ch[s[i]] = a[i];
      was[a[i]] = 1;
    } else {
      if (ch[s[i]] != a[i]) {
        cout << "NO\n";
        return;
      }
    }
    i++;
  }
  if (i == n) {
    get(n);
    return;
  }
  int cur = 0;
  if (ch[s[i]] && (ch[s[i]] < a[i] || ch[s[i]] > b[i])) {
    cout << "NO\n";
    return;
  }
  if (!ch[s[i]])
    for (int j = a[i] + 1; j < b[i]; j++) {
      if (!was[j]) cur = j;
    }
  if (cur != 0 || (ch[s[i]] > a[i] && ch[s[i]] < b[i])) {
    if (!ch[s[i]]) {
      ch[s[i]] = cur;
      was[cur] = 1;
    }
    get(i + 1);
    return;
  }
  if (ch[s[i]] == a[i] || (!ch[s[i]] && !was[a[i]])) {
    set<char> r;
    if (!was[a[i]]) r.insert(a[i]);
    ch[s[i]] = a[i];
    was[a[i]] = 1;
    int j = i + 1;
  ff:
    while (j < n && ch[s[j]] && ch[s[j]] == a[j]) j++;
    if (j == n) {
      get(n);
      return;
    }
    if (ch[s[j]] && ch[s[j]] > a[j]) {
      get(j + 1);
      return;
    }
    if (!ch[s[j]]) {
      int cur = 0;
      for (int o = k - 1 + 'a'; o >= a[j]; o--)
        if (!was[o]) {
          cur = o;
          break;
        }
      if (cur == a[j]) {
        ch[s[j]] = cur;
        was[cur] = 1;
        r.insert(cur);
        goto ff;
      }
      if (cur > a[j]) {
        ch[s[j]] = cur;
        was[cur] = 1;
        r.insert(cur);
        get(j + 1);
        return;
      }
    }
    for (int o = 'a'; o < 'a' + k; o++)
      if (r.find(ch[o]) != r.end()) ch[o] = 0;
    for (auto o : r) was[o] = 0;
  }
  if (ch[s[i]] == b[i] || (!ch[s[i]] && !was[b[i]])) {
    ch[s[i]] = b[i];
    was[b[i]] = 1;
    int j = i + 1;
  ff1:
    while (j < n && ch[s[j]] && ch[s[j]] == b[j]) j++;
    if (j == n) {
      get(n);
      return;
    }
    if (ch[s[j]] && ch[s[j]] < b[j]) {
      get(j + 1);
      return;
    }
    if (!ch[s[j]]) {
      int cur = 1000;
      for (int o = 'a'; o <= b[j]; o++)
        if (!was[o]) {
          cur = o;
          break;
        }
      if (cur == b[j]) {
        ch[s[j]] = cur;
        was[cur] = 1;
        goto ff1;
      }
      if (cur < b[j]) {
        ch[s[j]] = cur;
        was[cur] = 1;
        get(j + 1);
        return;
      }
    }
  }
  cout << "NO\n";
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  for (int i = 0; i < (t); i++) {
    cin >> k;
    cin >> s >> a >> b;
    go();
  }
  return 0;
}
