#include <bits/stdc++.h>
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(char s) { return string(1, s); }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A>
string to_string(A);
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool f = 1;
  string r = "{";
  for (const auto& x : v) {
    if (!f) r += ", ";
    f = 0;
    r += to_string(x);
  }
  return r + "}";
}
void debug_out() { cout << endl; }
void show() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << " " << to_string(H);
  debug_out(T...);
}
template <typename Head, typename... Tail>
void show(Head H, Tail... T) {
  cout << H << " ";
  show(T...);
}
const int MOD = 1e9 + 7;
const int N = 1000000 + 10;
int n, v[N], a[N], b[N];
int vis[27];
set<int> available;
int k;
bool link(int id, int x) {
  if (available.find(x) == available.end()) return 0;
  available.erase(x);
  vis[id] = x;
  return 1;
}
void removelink(int id, int x) {
  available.insert(x);
  vis[id] = -1;
}
bool l(int id) {
  int temp[27];
  for (int i = 0; i < 27; ++i) {
    temp[i] = vis[i];
  }
  bool ans = 1;
  for (int i = id; i <= n - 1; i++) {
    if (vis[v[i]] != -1) {
      if (vis[v[i]] > a[i]) return 1;
      if (vis[v[i]] < a[i]) {
        ans = 0;
        break;
      }
    } else {
      auto it = available.upper_bound(a[i]);
      if (!available.empty() and it != available.end() and (*it) < k) {
        int curr = (*it);
        link(v[i], curr);
        return 1;
      }
      if (link(v[i], a[i])) continue;
      ans = 0;
      break;
    }
  }
  if (ans) return 1;
  for (int i = 0; i < 27; ++i) {
    if (vis[i] != -1 and temp[i] == -1) {
      removelink(i, vis[i]);
    }
    vis[i] = temp[i];
  }
  return 0;
}
bool r(int id) {
  int temp[27];
  for (int i = 0; i < 27; ++i) {
    temp[i] = vis[i];
  }
  bool ans = 1;
  for (int i = id; i <= n - 1; i++) {
    if (vis[v[i]] != -1) {
      if (vis[v[i]] > b[i]) {
        ans = 0;
        break;
      }
      if (vis[v[i]] < b[i]) return 1;
    } else {
      auto it = available.lower_bound(b[i]);
      if (!available.empty() and it != available.begin()) {
        it--;
        int curr = (*it);
        link(v[i], curr);
        return 1;
      }
      if (link(v[i], b[i])) continue;
      ans = 0;
      break;
    }
  }
  if (ans) return 1;
  for (int i = 0; i < 27; ++i) {
    if (vis[i] != -1 and temp[i] == -1) {
      removelink(i, vis[i]);
    }
    vis[i] = temp[i];
  }
  return 0;
}
void solve() {
  cin >> k;
  for (int i = 0; i <= k + 1; i++) vis[i] = -1;
  for (int i = 0; i < k; ++i) {
    available.insert(i);
  }
  string s, x, y;
  cin >> s >> x >> y;
  n = s.size();
  for (int i = 0; i < n; ++i) {
    v[i] = (s[i] - 'a');
    a[i] = (x[i] - 'a');
    b[i] = (y[i] - 'a');
  }
  for (int i = 0; i < n; ++i) {
    if (vis[v[i]] != -1) {
      if (vis[v[i]] < a[i] or vis[v[i]] > b[i]) {
        cout << "NO" << '\n';
        return;
        ;
      }
      if (vis[v[i]] > a[i] and vis[v[i]] < b[i]) break;
      if (vis[v[i]] == a[i] and vis[v[i]] == b[i]) continue;
      if (vis[v[i]] == a[i]) {
        if (l(i + 1)) break;
        cout << "NO" << '\n';
        return;
        ;
      } else if (vis[v[i]] == b[i]) {
        if (r(i + 1)) break;
        cout << "NO" << '\n';
        return;
        ;
      }
      cout << "NO" << '\n';
      return;
      ;
    }
    if (a[i] == b[i]) {
      if (!link(v[i], a[i])) {
        cout << "NO" << '\n';
        return;
        ;
      }
    }
    if (a[i] == b[i] - 1) {
      if (link(v[i], a[i])) {
        if (l(i + 1)) break;
        removelink(v[i], a[i]);
      }
      if (link(v[i], b[i])) {
        if (r(i + 1)) break;
        cout << "NO" << '\n';
        return;
        ;
      }
      cout << "NO" << '\n';
      return;
      ;
    }
    if (a[i] < b[i] - 1) {
      auto it = available.upper_bound(a[i]);
      if (!available.empty() and it != available.end() and (*it) < b[i]) {
        int curr = (*it);
        link(v[i], curr);
        break;
      }
      if (link(v[i], a[i])) {
        if (l(i + 1)) break;
        removelink(v[i], a[i]);
      }
      if (link(v[i], b[i])) {
        if (r(i + 1)) break;
        cout << "NO" << '\n';
        return;
        ;
      }
      cout << "NO" << '\n';
      return;
      ;
    }
  }
  for (int i = 0; i < k; ++i) {
    if (vis[i] == -1) {
      vis[i] = (*available.begin());
      available.erase(available.begin());
    }
  }
  show("YES");
  for (int i = 0; i < k; ++i) {
    cout << char('a' + vis[i]);
  }
  cout << '\n';
}
int32_t main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
