#include <bits/stdc++.h>
char a[3000005], b[3000005];
char s[3000005];
int fix[30], map[30], used[30];
int doEqual(int k, int n) {
  for (int i = 1; i <= k; i++) {
    map[i] = fix[i] = used[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    int u = s[i] - 'a' + 1;
    int v = a[i] - 'a' + 1;
    if (fix[u]) {
      if (map[u] != v) return 0;
    } else {
      if (used[v]) return 0;
      used[v] = 1;
      fix[u] = 1;
      map[u] = v;
    }
  }
  return 1;
}
void fullFill(int k) {
  printf("YES\n");
  for (int i = 1; i <= k; i++) {
    if (fix[i] == 0) {
      int find = -1;
      for (int j = 1; j <= k; j++) {
        if (!used[j]) {
          find = j;
          break;
        }
      }
      used[find] = 1;
      fix[i] = 1;
      map[i] = find;
    }
    printf("%c", map[i] - 1 + 'a');
  }
  printf("\n");
}
int getSmaller(int p, int k, int n) {
  for (int i = p; i <= n; i++) {
    int u = s[i] - 'a' + 1, v = b[i] - 'a' + 1;
    if (fix[u]) {
      if (map[u] > v) return 0;
      if (map[u] < v) return 1;
    } else {
      int find = -1;
      for (int j = 1; j <= v - 1; j++) {
        if (!used[j]) {
          find = j;
          break;
        }
      }
      if (find != -1) {
        used[find] = 1;
        fix[u] = 1;
        map[u] = find;
        return 1;
      } else {
        if (used[v])
          return 0;
        else {
          used[v] = 1;
          fix[u] = 1;
          map[u] = v;
        }
      }
    }
  }
  return 1;
}
int getBigger(int p, int k, int n) {
  for (int i = p; i <= n; i++) {
    int u = s[i] - 'a' + 1, v = a[i] - 'a' + 1;
    if (fix[u]) {
      if (map[u] < v) return 0;
      if (map[u] > v) return 1;
    } else {
      int find = -1;
      for (int j = v + 1; j <= k; j++) {
        if (!used[j]) {
          find = j;
          break;
        }
      }
      if (find != -1) {
        used[find] = 1;
        fix[u] = 1;
        map[u] = find;
        return 1;
      } else {
        if (used[v])
          return 0;
        else {
          used[v] = 1;
          fix[u] = 1;
          map[u] = v;
        }
      }
    }
  }
  return 1;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int k;
    scanf("%d%s%s%s", &k, s + 1, a + 1, b + 1);
    int n = strlen(s + 1);
    int p = 0;
    while (p + 1 <= n && a[p + 1] == b[p + 1]) p++;
    for (int i = 1; i <= k; i++) used[i] = fix[i] = map[i] = 0;
    if (!doEqual(k, p))
      printf("NO\n");
    else {
      if (p == n) {
        fullFill(k);
      } else {
        p++;
        int u = s[p] - 'a' + 1;
        int va = a[p] - 'a' + 1, vb = b[p] - 'a' + 1;
        if (fix[u]) {
          if (map[u] < va || map[u] > vb)
            printf("NO\n");
          else if (map[u] > va && map[u] < vb) {
            fullFill(k);
          } else {
            if (map[u] == va) {
              if (getBigger(p + 1, k, n)) {
                fullFill(k);
              } else
                printf("NO\n");
            } else {
              if (getSmaller(p + 1, k, n)) {
                fullFill(k);
              } else
                printf("NO\n");
            }
          }
        } else {
          int find = -1;
          for (int i = va + 1; i <= vb - 1; i++) {
            if (!used[i]) {
              find = i;
              break;
            }
          }
          if (find != -1) {
            used[find] = 1;
            fix[u] = 1;
            map[u] = find;
            fullFill(k);
          } else {
            int find = -1;
            if (!used[va]) {
              used[va] = 1;
              fix[u] = 1;
              map[u] = va;
              if (getBigger(p + 1, k, n)) find = 1;
            }
            if (find == -1) {
              doEqual(k, p - 1);
              if (!used[vb]) {
                used[vb] = 1;
                fix[u] = 1;
                map[u] = vb;
                if (getSmaller(p + 1, k, n)) find = 1;
              }
            }
            if (find != -1) {
              fullFill(k);
            } else
              printf("NO\n");
          }
        }
      }
    }
  }
  return 0;
}
