#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007LL;
long long large = 2000000000000000000LL;
int k;
int n;
char t[1000010];
int s[1000010], a[1000010], b[1000010];
void f(string s, int a[]) {
  for (int i = 0; i < n; i++) {
    a[i] = (int)(s[i] - 'a');
  }
}
int main() {
  int test;
  cin >> test;
  while (test--) {
    scanf("%d", &k);
    scanf("%s", t);
    n = strlen(t);
    f(t, s);
    scanf("%s", t);
    f(t, a);
    scanf("%s", t);
    f(t, b);
    vector<int> map(k, -1);
    vector<bool> op(k, false);
    bool can = true;
    int i = 0;
    for (i = 0; i < n; i++) {
      if (a[i] == b[i]) {
        if (map[s[i]] != -1) {
          if (map[s[i]] != a[i]) {
            can = false;
            break;
          }
        } else {
          if (op[a[i]]) {
            can = false;
            break;
          }
          map[s[i]] = a[i];
          op[a[i]] = true;
        }
      } else {
        break;
      }
    }
    if (!can) {
      printf("NO\n");
      continue;
    }
    if (i == n) {
      printf("YES\n");
      int j = 0;
      for (int i = 0; i < k; i++) {
        if (map[i] == -1) {
          for (; j < k; j++) {
            if (!op[j]) {
              map[i] = j;
              op[j] = true;
              break;
            }
          }
        }
      }
      for (int i = 0; i < k; i++) printf("%c", (char)(map[i] + 'a'));
      printf("\n");
      continue;
    }
    if (map[s[i]] != -1) {
      if (map[s[i]] > a[i] && map[s[i]] < b[i]) {
        printf("YES\n");
        int j = 0;
        for (int i = 0; i < k; i++) {
          if (map[i] == -1) {
            for (; j < k; j++) {
              if (!op[j]) {
                map[i] = j;
                op[j] = true;
                break;
              }
            }
          }
        }
        for (int i = 0; i < k; i++) printf("%c", (char)(map[i] + 'a'));
        printf("\n");
        continue;
      } else {
        if (map[s[i]] == a[i]) {
          i++;
          for (; i < n; i++) {
            if (map[s[i]] == -1) {
              for (int j = a[i] + 1; j < k; j++) {
                if (!op[j]) {
                  map[s[i]] = j;
                  op[j] = true;
                  break;
                }
              }
              if (map[s[i]] != -1) break;
              if (op[a[i]]) {
                can = false;
                break;
              }
              map[s[i]] = a[i];
              op[a[i]] = true;
            } else {
              if (map[s[i]] > a[i]) break;
              if (map[s[i]] < a[i]) {
                can = false;
                break;
              }
            }
          }
          if (can) {
            printf("YES\n");
            int j = 0;
            for (int i = 0; i < k; i++) {
              if (map[i] == -1) {
                for (; j < k; j++) {
                  if (!op[j]) {
                    map[i] = j;
                    op[j] = true;
                    break;
                  }
                }
              }
            }
            for (int i = 0; i < k; i++) printf("%c", (char)(map[i] + 'a'));
            printf("\n");
            continue;
          } else {
            printf("NO\n");
            continue;
          }
        } else if (map[s[i]] == b[i]) {
          i++;
          for (; i < n; i++) {
            if (map[s[i]] == -1) {
              for (int j = b[i] - 1; j >= 0; j--) {
                if (!op[j]) {
                  map[s[i]] = j;
                  op[j] = true;
                  break;
                }
              }
              if (map[s[i]] != -1) break;
              if (op[b[i]]) {
                can = false;
                break;
              }
              map[s[i]] = b[i];
              op[b[i]] = true;
            } else {
              if (map[s[i]] < b[i]) break;
              if (map[s[i]] > b[i]) {
                can = false;
                break;
              }
            }
          }
          if (can) {
            printf("YES\n");
            int j = 0;
            for (int i = 0; i < k; i++) {
              if (map[i] == -1) {
                for (; j < k; j++) {
                  if (!op[j]) {
                    map[i] = j;
                    op[j] = true;
                    break;
                  }
                }
              }
            }
            for (int i = 0; i < k; i++) printf("%c", (char)(map[i] + 'a'));
            printf("\n");
            continue;
          } else {
            printf("NO\n");
            continue;
          }
        }
        printf("NO\n");
        continue;
      }
    } else {
      for (int j = a[i] + 1; j <= b[i] - 1; j++) {
        if (!op[j]) {
          map[s[i]] = j;
          op[j] = true;
          break;
        }
      }
      if (map[s[i]] != -1) {
        printf("YES\n");
        int j = 0;
        for (int i = 0; i < k; i++) {
          if (map[i] == -1) {
            for (; j < k; j++) {
              if (!op[j]) {
                map[i] = j;
                op[j] = true;
                break;
              }
            }
          }
        }
        for (int i = 0; i < k; i++) printf("%c", (char)(map[i] + 'a'));
        printf("\n");
        continue;
      }
      vector<int> tmap = map;
      int tpos = i;
      vector<bool> top = op;
      if (!op[a[i]]) {
        map[s[i]] = a[i];
        op[a[i]] = true;
        i++;
        for (; i < n; i++) {
          if (map[s[i]] == -1) {
            for (int j = a[i] + 1; j < k; j++) {
              if (!op[j]) {
                map[s[i]] = j;
                op[j] = true;
                break;
              }
            }
            if (map[s[i]] != -1) break;
            if (op[a[i]]) {
              can = false;
              break;
            }
            map[s[i]] = a[i];
            op[a[i]] = true;
          } else {
            if (map[s[i]] > a[i]) break;
            if (map[s[i]] < a[i]) {
              can = false;
              break;
            }
          }
        }
        if (can) {
          printf("YES\n");
          int j = 0;
          for (int i = 0; i < k; i++) {
            if (map[i] == -1) {
              for (; j < k; j++) {
                if (!op[j]) {
                  map[i] = j;
                  op[j] = true;
                  break;
                }
              }
            }
          }
          for (int i = 0; i < k; i++) printf("%c", (char)(map[i] + 'a'));
          printf("\n");
          continue;
        }
      }
      map = tmap;
      op = top;
      i = tpos;
      can = true;
      if (!op[b[i]]) {
        map[s[i]] = b[i];
        op[b[i]] = true;
        i++;
        for (; i < n; i++) {
          if (map[s[i]] == -1) {
            for (int j = b[i] - 1; j >= 0; j--) {
              if (!op[j]) {
                map[s[i]] = j;
                op[j] = true;
                break;
              }
            }
            if (map[s[i]] != -1) break;
            if (op[b[i]]) {
              can = false;
              break;
            }
            map[s[i]] = b[i];
            op[b[i]] = true;
          } else {
            if (map[s[i]] < b[i]) break;
            if (map[s[i]] > b[i]) {
              can = false;
              break;
            }
          }
        }
        if (can) {
          printf("YES\n");
          int j = 0;
          for (int i = 0; i < k; i++) {
            if (map[i] == -1) {
              for (; j < k; j++) {
                if (!op[j]) {
                  map[i] = j;
                  op[j] = true;
                  break;
                }
              }
            }
          }
          for (int i = 0; i < k; i++) printf("%c", (char)(map[i] + 'a'));
          printf("\n");
          continue;
        }
      }
      printf("NO\n");
      continue;
    }
  }
  return 0;
}
