#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
char s[MAXN], a[MAXN], b[MAXN];
int ans[30], sv[30];
bool book[30], tmp[30];
int n, k;
void getfree() {
  for (int i = 0; i < k; i++) {
    if (ans[i] != -1) continue;
    for (int j = 0; j < k; j++) {
      if (book[j]) continue;
      ans[i] = j;
      book[j] = true;
      break;
    }
  }
}
bool getlow(int st) {
  for (int i = st; i <= n; i++) {
    if (ans[s[i]] == -1) {
      for (int j = a[i] + 1; j < k; j++) {
        if (book[j]) continue;
        ans[s[i]] = j;
        book[j] = true;
        getfree();
        return true;
      }
      if (book[a[i]]) return false;
      ans[s[i]] = a[i];
      book[a[i]] = true;
    } else {
      if (ans[s[i]] < a[i])
        return false;
      else if (ans[s[i]] > a[i]) {
        getfree();
        return true;
      }
    }
  }
  return true;
}
bool gethigh(int st) {
  for (int i = st; i <= n; i++) {
    if (ans[s[i]] == -1) {
      for (int j = 0; j < b[i]; j++) {
        if (book[j]) continue;
        ans[s[i]] = j;
        book[j] = true;
        getfree();
        return true;
      }
      if (book[b[i]]) return false;
      ans[s[i]] = b[i];
      book[b[i]] = true;
    } else {
      if (ans[s[i]] > b[i])
        return false;
      else if (ans[s[i]] < b[i]) {
        getfree();
        return true;
      }
    }
  }
  return true;
}
int solve() {
  memset(book, false, sizeof(book));
  memset(ans, -1, sizeof(ans));
  scanf("%d", &k);
  scanf("%s", s + 1);
  scanf("%s", a + 1);
  scanf("%s", b + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) a[i] -= 'a', b[i] -= 'a', s[i] -= 'a';
  for (int i = 1; i <= n; i++) {
    if (a[i] == b[i]) {
      if (ans[s[i]] == -1) {
        if (book[a[i]]) return 0 * puts("NO");
        ans[s[i]] = a[i];
        book[a[i]] = true;
      } else if (ans[s[i]] == a[i])
        continue;
      else
        return 0 * puts("NO");
    } else {
      if (ans[s[i]] == -1) {
        if (!book[a[i]]) {
          memcpy(tmp, book, sizeof(book));
          memcpy(sv, ans, sizeof(ans));
          ans[s[i]] = a[i];
          book[a[i]] = true;
          if (getlow(i + 1))
            break;
          else {
            memcpy(book, tmp, sizeof(book));
            memcpy(ans, sv, sizeof(ans));
          }
        }
        if (!book[b[i]]) {
          memcpy(tmp, book, sizeof(book));
          memcpy(sv, ans, sizeof(ans));
          ans[s[i]] = b[i];
          book[b[i]] = true;
          if (gethigh(i + 1))
            break;
          else {
            memcpy(book, tmp, sizeof(book));
            memcpy(ans, sv, sizeof(ans));
          }
        }
        bool flag = false;
        for (int j = a[i] + 1; j < b[i]; j++) {
          if (!book[j]) {
            flag = true;
            ans[s[i]] = j;
            book[j] = true;
            getfree();
            break;
          }
        }
        if (flag)
          break;
        else
          return 0 * puts("NO");
      } else {
        if (ans[s[i]] == a[i]) {
          if (getlow(i + 1)) {
            break;
          } else
            return 0 * puts("NO");
        } else if (ans[s[i]] == b[i]) {
          if (gethigh(i + 1)) {
            break;
          } else
            return 0 * puts("NO");
        } else if (ans[s[i]] < a[i] || ans[s[i]] > b[i]) {
          return 0 * puts("NO");
        } else {
          getfree();
        }
      }
      break;
    }
  }
  getfree();
  puts("YES");
  for (int i = 0; i < k; i++) {
    printf("%c", ans[i] + 'a');
  }
  puts("");
  return 0;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    solve();
  }
  return 0;
}
