#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
string s, a, b;
int n, k;
bool finished;
bool success;
vector<char> ans;
void dfs(vector<char> vec, bool gtA, bool ltB, int cnt) {
  if (finished) {
    return;
  }
  if (gtA && ltB) {
    ans = vec;
    finished = true;
    return;
  }
  if (cnt >= n) {
    ans = vec;
    finished = true;
    return;
  }
  int pos = s.at(cnt) - 'a';
  vector<bool> used(26);
  for (auto e : vec) {
    if (e != '?') {
      used.at(e - 'a') = true;
    }
  }
  if (gtA) {
    if (vec.at(pos) == '?') {
      for (int i = 0; i < (int)(k); i++) {
        if (!used.at(i)) {
          if ('a' + i < b.at(cnt)) {
            vec.at(pos) = 'a' + i;
            ans = vec;
            finished = true;
            return;
          } else if ('a' + i == b.at(cnt)) {
            vec.at(pos) = 'a' + i;
            dfs(vec, true, false, cnt + 1);
          } else {
            break;
          }
        }
      }
    } else {
      if (vec.at(pos) < b.at(cnt)) {
        ans = vec;
        finished = true;
        return;
      } else if (vec.at(pos) == b.at(cnt)) {
        dfs(vec, true, false, cnt + 1);
      }
    }
  } else if (ltB) {
    if (vec.at(pos) == '?') {
      for (int i = k - 1; i >= 0; i--) {
        if (!used.at(i)) {
          if ('a' + i > a.at(cnt)) {
            vec.at(pos) = 'a' + i;
            ans = vec;
            finished = true;
            return;
          } else if ('a' + i == a.at(cnt)) {
            vec.at(pos) = 'a' + i;
            dfs(vec, false, true, cnt + 1);
          } else {
            break;
          }
        }
      }
    } else {
      if (vec.at(pos) > a.at(cnt)) {
        ans = vec;
        finished = true;
        return;
      } else if (vec.at(pos) == a.at(cnt)) {
        dfs(vec, false, true, cnt + 1);
      }
    }
  } else {
    if (vec.at(pos) == '?') {
      int apos = a.at(cnt) - 'a';
      int bpos = b.at(cnt) - 'a';
      for (int i = apos + 1; i < bpos; i++) {
        if (!used.at(i)) {
          vec.at(pos) = 'a' + i;
          ans = vec;
          finished = true;
          return;
        }
      }
      if (apos < bpos) {
        if (!used.at(apos)) {
          vector<char> vec2 = vec;
          vec2.at(pos) = 'a' + apos;
          dfs(vec2, false, true, cnt + 1);
        }
        if (!used.at(bpos)) {
          vector<char> vec2 = vec;
          vec2.at(pos) = 'a' + bpos;
          dfs(vec2, true, false, cnt + 1);
        }
      } else {
        if (!used.at(apos)) {
          vec.at(pos) = 'a' + apos;
          dfs(vec, false, false, cnt + 1);
        }
      }
    } else {
      if (a.at(cnt) < vec.at(pos) && vec.at(pos) < b.at(cnt)) {
        ans = vec;
        finished = true;
        return;
      } else if (a.at(cnt) == vec.at(pos) && vec.at(pos) < b.at(cnt)) {
        dfs(vec, false, true, cnt + 1);
      } else if (a.at(cnt) < vec.at(pos) && vec.at(pos) == b.at(cnt)) {
        dfs(vec, true, false, cnt + 1);
      } else if (a.at(cnt) == vec.at(pos) && vec.at(pos) == b.at(cnt)) {
        dfs(vec, false, false, cnt + 1);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  for (int ignore = 0; ignore < (int)(t); ignore++) {
    cin >> k;
    cin >> s >> a >> b;
    n = s.size();
    vector<char> vec(k);
    for (int i = 0; i < (int)(k); i++) {
      vec.at(i) = '?';
    }
    finished = false;
    dfs(vec, false, false, 0);
    if (!finished) {
      cout << "NO" << '\n';
      continue;
    }
    cout << "YES" << '\n';
    vector<bool> used(26);
    for (auto e : ans) {
      if (e != '?') {
        used.at(e - 'a') = true;
      }
    }
    for (int i = 0; i < (int)(k); i++) {
      if (ans.at(i) == '?') {
        for (int j = 0; j < (int)(k); j++) {
          if (!used.at(j)) {
            ans.at(i) = 'a' + j;
            used.at(j) = true;
            break;
          }
        }
      }
    }
    for (int i = 0; i < (int)(k); i++) {
      cout << ans.at(i);
    }
    cout << '\n';
  }
}
