#include <bits/stdc++.h>
using namespace std;
int t, n, k;
char s[1000010], a[1000010], b[1000010];
char which[1000010];
bool solve(bool goa) {
  for (int i = 'a'; i < 'a' + k; i++) which[i] = '?';
  set<char> rem;
  for (int i = 'a'; i < 'a' + k; i++) rem.insert(i);
  bool ok = true;
  bool normal = true;
  for (int i = 0; i < n; i++) {
    if (!normal) {
      if (goa) {
        if (which[s[i]] == '?') {
          if (*rem.rbegin() > a[i]) {
            which[s[i]] = *rem.rbegin();
            rem.erase(rem.find(*rem.rbegin()));
            break;
          } else if (*rem.rbegin() < a[i]) {
            ok = false;
            break;
          } else {
            which[s[i]] = *rem.rbegin();
            rem.erase(rem.find(*rem.rbegin()));
          }
        } else {
          if (which[s[i]] > a[i]) {
            break;
          }
          if (which[s[i]] < a[i]) {
            ok = false;
            break;
          }
        }
      } else {
        if (which[s[i]] == '?') {
          if (*rem.begin() < b[i]) {
            which[s[i]] = *rem.begin();
            rem.erase(rem.find(*rem.begin()));
            break;
          } else if (*rem.begin() > b[i]) {
            ok = false;
            break;
          } else {
            which[s[i]] = *rem.begin();
            rem.erase(rem.find(*rem.begin()));
          }
        } else {
          if (which[s[i]] < b[i]) {
            break;
          }
          if (which[s[i]] > b[i]) {
            ok = false;
            break;
          }
        }
      }
    } else {
      if (a[i] == b[i]) {
        if (which[s[i]] == '?') {
          if (rem.count(a[i])) {
            which[s[i]] = a[i];
            rem.erase(rem.find(a[i]));
          } else {
            ok = false;
            break;
          }
        } else if (which[s[i]] != a[i]) {
          ok = false;
          break;
        }
      } else {
        if (which[s[i]] == '?') {
          bool fnd = false;
          for (int j = a[i] + 1; j < b[i]; j++) {
            if (rem.count(j)) {
              which[s[i]] = j;
              rem.erase(rem.find(j));
              fnd = true;
              break;
            }
          }
          if (fnd) {
            ok = true;
            break;
          } else {
            if (goa) {
              if (rem.count(a[i])) {
                normal = false;
                which[s[i]] = a[i];
                rem.erase(rem.find(a[i]));
              } else {
                ok = false;
                break;
              }
            } else {
              if (rem.count(b[i])) {
                normal = false;
                which[s[i]] = b[i];
                rem.erase(rem.find(b[i]));
              } else {
                ok = false;
                break;
              }
            }
          }
        } else {
          if (which[s[i]] < a[i] || which[s[i]] > b[i]) {
            ok = false;
            break;
          } else if (which[s[i]] > a[i] && which[s[i]] < b[i]) {
            break;
          } else {
            if (which[s[i]] == a[i]) {
              if (goa)
                normal = false;
              else {
                ok = false;
                break;
              }
            } else {
              if (!goa)
                normal = false;
              else {
                ok = false;
                break;
              }
            }
          }
        }
      }
    }
  }
  if (!ok)
    return false;
  else {
    for (int i = 'a'; i < 'a' + k; i++) {
      if (which[i] == '?') {
        which[i] = *rem.begin();
        rem.erase(rem.begin());
      }
    }
    printf("YES\n");
    for (int i = 'a'; i < 'a' + k; i++) printf("%c", which[i]);
    printf("\n");
    return true;
  }
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &k);
    scanf("%s", s);
    scanf("%s", a);
    scanf("%s", b);
    n = strlen(s);
    if (solve(true)) continue;
    if (solve(false)) continue;
    printf("NO\n");
  }
}
