#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
char s[maxn], a[maxn], b[maxn];
int mp[33];
int k, len;
bool vis[33];
bool dfs(int i, bool Greater, bool Smaller) {
  if ((Greater && Smaller) || i == len + 1) return 1;
  if (mp[s[i] - 'a' + 1] > 0) {
    if (!Greater && mp[s[i] - 'a' + 1] < a[i] - 'a' + 1) return 0;
    if (!Smaller && mp[s[i] - 'a' + 1] > b[i] - 'a' + 1) return 0;
    return dfs(i + 1, Greater || mp[s[i] - 'a' + 1] > a[i] - 'a' + 1,
               Smaller || mp[s[i] - 'a' + 1] < b[i] - 'a' + 1);
  } else {
    int down = Greater ? 1 : a[i] - 'a' + 1;
    int up = Smaller ? k : b[i] - 'a' + 1;
    for (int j = down; j <= up; j++) {
      if (mp[s[i] - 'a' + 1] || vis[j]) continue;
      mp[s[i] - 'a' + 1] = j;
      vis[j] = 1;
      if (dfs(i + 1, Greater || j > a[i] - 'a' + 1,
              Smaller || j < b[i] - 'a' + 1))
        return 1;
      mp[s[i] - 'a' + 1] = 0;
      vis[j] = 0;
    }
  }
  return 0;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    memset(mp, 0, sizeof(mp));
    memset(vis, 0, sizeof(vis));
    scanf("%d%s%s%s", &k, s + 1, a + 1, b + 1);
    len = strlen(s + 1);
    if (dfs(1, 0, 0)) {
      printf("YES\n");
      for (int i = 1; i <= k; i++) {
        if (!mp[i]) {
          for (int j = 1; j <= k; j++) {
            if (!vis[j]) {
              mp[i] = j;
              vis[j] = 1;
              break;
            }
          }
        }
      }
      for (int i = 1; i <= k; i++) printf("%c", mp[i] + 'a' - 1);
      printf("\n");
    } else
      printf("NO\n");
  }
  return 0;
}
