#include <bits/stdc++.h>
using namespace std;
int nxt[30], prv[30], k;
bool isCorrect, isFinished;
vector<pair<int, int>> edges;
bool canAdd(int from, int to) {
  return (nxt[from] == to) || (nxt[from] == -1 && prv[to] == -1);
}
void addEdge(int from, int to) {
  if (nxt[from] == to) {
    return;
  }
  if (nxt[from] != -1) {
    isCorrect = false;
    return;
  }
  if (prv[to] != -1) {
    isCorrect = false;
    return;
  }
  nxt[from] = to;
  prv[to] = from;
  edges.push_back(make_pair(from, to));
}
void finish() {
  for (int i = 0; i < k; ++i) {
    if (nxt[i] == -1) {
      int cur = i;
      while (prv[cur] != -1) {
        cur = prv[cur];
      }
      nxt[i] = cur;
    }
  }
  isFinished = true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int cases;
  cin >> cases;
  while (cases--) {
    string a, b, s;
    cin >> k;
    for (int i = 0; i < k; ++i) {
      nxt[i] = -1;
      prv[i] = -1;
    }
    isCorrect = true;
    isFinished = false;
    edges.clear();
    cin >> s >> a >> b;
    size_t pos;
    for (pos = 0; pos < s.size(); ++pos) {
      if (a[pos] != b[pos]) {
        break;
      }
      addEdge(s[pos] - 'a', a[pos] - 'a');
    }
    if (pos != s.size()) {
      for (int i = a[pos] - 'a' + 1; i <= b[pos] - 'a' - 1; ++i) {
        if (canAdd(s[pos] - 'a', i)) {
          addEdge(s[pos] - 'a', i);
          finish();
          break;
        }
      }
    } else {
      if (isCorrect) {
        isFinished = true;
      }
    }
    if (!isFinished && isCorrect) {
      vector<pair<int, int>> curEdges = edges;
      addEdge(s[pos] - 'a', a[pos] - 'a');
      for (size_t i = pos + 1; i < s.size(); ++i) {
        for (int cur = a[i] - 'a' + 1; cur < k; ++cur) {
          if (canAdd(s[i] - 'a', cur)) {
            addEdge(s[i] - 'a', cur);
            finish();
            break;
          }
        }
        if (isFinished) {
          break;
        }
        addEdge(s[i] - 'a', a[i] - 'a');
      }
      finish();
      if (!isCorrect) {
        for (int i = 0; i < k; ++i) {
          nxt[i] = -1;
          prv[i] = -1;
        }
        for (auto P : curEdges) {
          nxt[P.first] = P.second;
          prv[P.second] = P.first;
        }
        edges = curEdges;
        isCorrect = true;
        isFinished = false;
        addEdge(s[pos] - 'a', b[pos] - 'a');
        for (size_t i = pos + 1; i < s.size(); ++i) {
          for (int cur = 0; cur < b[i] - 'a'; ++cur) {
            if (canAdd(s[i] - 'a', cur)) {
              addEdge(s[i] - 'a', cur);
              finish();
              break;
            }
          }
          if (isFinished) {
            break;
          }
          addEdge(s[i] - 'a', b[i] - 'a');
        }
      }
    }
    if (isCorrect) {
      finish();
      cout << "YES"
           << "\n";
      for (int i = 0; i < k; ++i) {
        cout << char(int('a') + nxt[i]);
      }
      cout << "\n";
    } else {
      cout << "NO"
           << "\n";
    }
  }
}
