#include <bits/stdc++.h>
using namespace std;
int t, n, k;
bool ok;
bool used[26];
char s[1000010], a[1000010], b[1000010];
map<char, char> mp;
bool check() {
  for (register int i = 1; i <= n; i++) {
    if (mp[s[i]] < b[i]) {
      return true;
    } else if (mp[s[i]] > b[i]) {
      return false;
    }
  }
  return true;
}
void dfs(int pos, bool lima, bool limb) {
  if (ok) return;
  if (pos == n + 1) {
    int tmp1[26], tmp2[26], cnt = 0;
    for (register int i = 0; i < k; i++) {
      if (mp[(char)('a' + i)] == '$') {
        tmp1[++cnt] = i;
        for (register int j = 0; j < k; j++) {
          if (!used[j]) {
            tmp2[cnt] = j;
            used[j] = true;
            mp[(char)('a' + i)] = (char)('a' + j);
            break;
          }
        }
      }
    }
    printf("YES\n");
    for (register int i = 0; i < k; i++) {
      printf("%c", mp[(char)('a' + i)]);
    }
    printf("\n");
    ok = true;
    return;
  }
  if (mp[s[pos]] != '$') {
    if ((lima && mp[s[pos]] < a[pos]) || (limb && mp[s[pos]] > b[pos])) {
      return;
    } else {
      dfs(pos + 1, lima && mp[s[pos]] == a[pos], limb && mp[s[pos]] == b[pos]);
      if (ok) return;
    }
  } else {
    int st = lima ? a[pos] - 'a' : 0;
    int up = limb ? b[pos] - 'a' : k - 1;
    for (register int i = st; i <= up; i++) {
      if (ok) return;
      if (!used[i]) {
        mp[s[pos]] = (char)('a' + i);
        used[i] = true;
        dfs(pos + 1, lima && i == st, limb && i == up);
        if (ok) return;
        used[i] = false;
        mp[s[pos]] = '$';
      }
    }
  }
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &k);
    scanf("%s", s + 1);
    scanf("%s", a + 1);
    scanf("%s", b + 1);
    n = strlen(s + 1);
    memset(used, false, sizeof(used));
    ok = false;
    for (register int i = 0; i < 26; i++) {
      mp[(char)('a' + i)] = '$';
    }
    dfs(1, true, true);
    if (!ok) {
      printf("NO\n");
    }
  }
  return 0;
  ;
}
