#include <bits/stdc++.h>
using namespace std;
char ss[1000005], a[1000005], b[1000005], ans[155], ans2[155];
int used[155], used2[155];
int read() {
  char c = getchar();
  int x = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
void print(int k) {
  printf("YES\n");
  for (int i = 'a'; i < 'a' + k; i++) {
    if (ans[i] == -1) {
      for (int j = 'a'; j < 'a' + k; j++) {
        if (!used[j]) {
          ans[i] = j;
          used[j] = 1;
          break;
        }
      }
    }
    printf("%c", ans[i]);
  }
  printf("\n");
}
bool checka(int st, int k, int len) {
  memcpy(ans2, ans, sizeof(ans));
  memcpy(used2, used, sizeof(used));
  if (ans2[ss[st - 1]] != -1) {
    if (ans2[ss[st - 1]] != a[st - 1]) return false;
  } else {
    if (!used2[a[st - 1]]) {
      ans2[ss[st - 1]] = a[st - 1];
      used2[a[st - 1]] = 1;
    } else
      return false;
  }
  for (int i = st; i <= len; i++) {
    if (ans2[ss[i]] != -1) {
      if (ans2[ss[i]] > a[i])
        return true;
      else if (ans2[ss[i]] == a[i])
        continue;
      else
        return false;
    }
    for (int j = a[i] + 1; j < 'a' + k; j++) {
      if (!used2[j]) {
        ans2[ss[i]] = j;
        used2[j] = 1;
        return true;
      }
    }
    if (!used2[a[i]]) {
      ans2[ss[i]] = a[i];
      used2[a[i]] = 1;
    } else
      return false;
  }
  return true;
}
bool checkb(int st, int k, int len) {
  memcpy(ans2, ans, sizeof(ans));
  memcpy(used2, used, sizeof(used));
  if (ans2[ss[st - 1]] != -1) {
    if (ans2[ss[st - 1]] != b[st - 1]) return false;
  } else {
    if (!used2[b[st - 1]]) {
      ans2[ss[st - 1]] = b[st - 1];
      used2[b[st - 1]] = 1;
    } else
      return false;
  }
  for (int i = st; i <= len; i++) {
    if (ans2[ss[i]] != -1) {
      if (ans2[ss[i]] < b[i])
        return true;
      else if (ans2[ss[i]] == b[i])
        continue;
      else
        return false;
    }
    for (int j = b[i] - 1; j >= 'a'; j--) {
      if (!used2[j]) {
        ans2[ss[i]] = j;
        used2[j] = 1;
        return true;
      }
    }
    if (!used2[b[i]]) {
      ans2[ss[i]] = b[i];
      used2[b[i]] = 1;
    } else
      return false;
  }
  return true;
}
int main() {
  int tt = read();
  while (tt--) {
    int k = read();
    scanf("%s", ss + 1);
    scanf("%s", a + 1);
    scanf("%s", b + 1);
    int len = strlen(ss + 1);
    for (char i = 'a'; i < 'a' + k; i++) ans[i] = -1, used[i] = 0;
    bool f = true;
    int st = len + 1;
    for (int i = 1; i <= len; i++) {
      if (a[i] == b[i]) {
        if (ans[ss[i]] == -1) {
          if (!used[a[i]]) {
            ans[ss[i]] = a[i];
            used[a[i]] = 1;
          } else {
            printf("NO\n");
            f = false;
            break;
          }
        } else if (ans[ss[i]] != a[i]) {
          printf("NO\n");
          f = false;
          break;
        }
      } else {
        st = i;
        break;
      }
    }
    if (!f) continue;
    if (st == len + 1) {
      print(k);
      continue;
    }
    f = true;
    if (ans[ss[st]] == -1) {
      for (int i = a[st] + 1; i < b[st]; i++) {
        if (!used[i]) {
          ans[ss[st]] = i;
          used[i] = 1;
          print(k);
          f = false;
          break;
        }
      }
    } else {
      if (a[st] < ans[ss[st]] && ans[ss[st]] < b[st]) {
        print(k);
        continue;
      } else if (ans[ss[st]] == a[st]) {
        if (checka(st + 1, k, len)) {
          memcpy(ans, ans2, sizeof(ans2));
          memcpy(used, used2, sizeof(used2));
          print(k);
          continue;
        }
      } else if (ans[ss[st]] == b[st]) {
        if (checkb(st + 1, k, len)) {
          memcpy(ans, ans2, sizeof(ans2));
          memcpy(used, used2, sizeof(used2));
          print(k);
          continue;
        }
      } else {
        printf("NO\n");
        continue;
      }
    }
    if (!f) continue;
    if (checka(st + 1, k, len)) {
      memcpy(ans, ans2, sizeof(ans2));
      memcpy(used, used2, sizeof(used2));
      print(k);
      continue;
    }
    if (checkb(st + 1, k, len)) {
      memcpy(ans, ans2, sizeof(ans2));
      memcpy(used, used2, sizeof(used2));
      print(k);
      continue;
    }
    printf("NO\n");
  }
  return 0;
}
