#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2")
using namespace std;
template <typename Tp>
inline void read(Tp &x) {
  x = 0;
  bool neg = false;
  char c = getchar();
  for (; !isdigit(c); c = getchar()) {
    if (c == '-') {
      neg = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (neg) {
    x = -x;
  }
}
const int N = 3e6 + 5;
int T, n, k;
char s[N], a[N], b[N];
struct Bijection {
  unordered_map<char, char> front;
  unordered_map<char, char> back;
  template <const bool SKIP_CHECK = false>
  inline bool insert(const char &f, const char &b) {
    if (!SKIP_CHECK) {
      auto iter = front.find(f);
      if (iter != front.end() && iter->second != b) {
        return false;
      }
      iter = back.find(b);
      if (iter != back.end() && iter->second != f) {
        return false;
      }
    }
    front.emplace(f, b);
    back.emplace(b, f);
    return true;
  }
  inline void autoFill() {
    static char f[26], b[26];
    int ft = 0, bt = 0;
    for (int i = 0; i < k; ++i) {
      char c = 'a' + i;
      if (!front.count(c)) {
        f[ft++] = c;
      }
      if (!back.count(c)) {
        b[bt++] = c;
      }
    }
    for (int i = 0; i < ft; ++i) {
      insert<true>(f[i], b[i]);
    }
  }
  inline void print() {
    for (int i = 0; i < k; ++i) {
      char c = 'a' + i;
      putchar(front[c]);
    }
    putchar('\n');
  }
  inline char findByKey(const char &key) {
    auto iter = front.find(key);
    if (iter == front.end()) {
      return (char)0;
    }
    return iter->second;
  }
  inline char findByVal(const char &val) {
    auto iter = back.find(val);
    if (iter == back.end()) {
      return char(0);
    }
    return iter->second;
  }
  inline bool insMin(const char &c) {
    for (int i = 0; i < k; ++i) {
      char d = 'a' + i;
      if (insert(c, d)) {
        return true;
      }
    }
    return false;
  }
  inline bool insMax(const char &c) {
    for (int i = k - 1; i >= 0; --i) {
      char d = 'a' + i;
      if (insert(c, d)) {
        return true;
      }
    }
    return false;
  }
};
inline void solve() {
  read(k);
  scanf("%s %s %s", s, a, b);
  int n = strlen(s);
  unordered_map<char, char> mp;
  Bijection bij;
  auto validateMin = [&]() {
    for (int i = 0; i < n; ++i) {
      char c = bij.findByKey(s[i]);
      if (c > a[i]) {
        return true;
      } else if (c < a[i]) {
        return false;
      }
    }
    return true;
  };
  auto validateMax = [&]() {
    for (int i = 0; i < n; ++i) {
      char c = bij.findByKey(s[i]);
      if (c < b[i]) {
        return true;
      } else if (c > b[i]) {
        return false;
      }
    }
    return true;
  };
  auto validate = [&]() { return validateMin() && validateMax(); };
  auto minimum = [&](int pos, bool melt) {
    for (; pos < n; ++pos) {
      if (!bij.findByKey(s[pos])) {
        bij.insMin(s[pos]);
      }
    }
    if (validate()) {
      puts("YES");
      bij.autoFill();
      bij.print();
      return true;
    } else {
      if (melt) {
        puts("NO");
      }
      return false;
    }
  };
  auto maximum = [&](int pos, bool melt) {
    for (; pos < n; ++pos) {
      if (!bij.findByKey(s[pos])) {
        bij.insMax(s[pos]);
      }
    }
    if (validate()) {
      puts("YES");
      bij.autoFill();
      bij.print();
      return true;
    } else {
      if (melt) {
        puts("NO");
      }
      return false;
    }
  };
  for (int i = 0; i < n; ++i) {
    if (a[i] == b[i]) {
      if (!bij.insert(s[i], a[i])) {
        puts("NO");
        return;
      }
    } else {
      char val = bij.findByKey(s[i]);
      if (val) {
        if (val > b[i] || val < a[i]) {
          puts("NO");
        } else if (val == a[i]) {
          maximum(i, true);
        } else if (val == b[i]) {
          minimum(i, true);
        } else if (a[i] < val && val < b[i]) {
          minimum(i, true);
        }
      } else {
        for (char c = a[i] + 1; c < b[i]; ++c) {
          if (bij.insert(s[i], c)) {
            minimum(i + 1, true);
            return;
          }
        }
        Bijection back = bij;
        if (bij.insert(s[i], a[i])) {
          if (maximum(i + 1, false)) {
            return;
          }
        }
        bij = back;
        if (bij.insert(s[i], b[i])) {
          if (minimum(i + 1, false)) {
            return;
          }
        }
        puts("NO");
      }
      return;
    }
  }
  puts("YES");
  bij.autoFill();
  bij.print();
}
int main() {
  read(T);
  for (int cas = 0; cas < T; ++cas) {
    solve();
  }
  return 0;
}
