#include <bits/stdc++.h>
using namespace std;
string s, a, b;
int k, n;
int in[30], out[30], memo_in[30], memo_out[30];
int diffPos = -1;
vector<int> missing_in;
vector<int> missing_out;
void build() {
  missing_in.clear();
  missing_out.clear();
  for (int i = 0; i < k; i++)
    if (in[i] == -1) missing_in.push_back(i);
  for (int i = 0; i < k; i++)
    if (out[i] == -1) missing_out.push_back(i);
  for (int i = 0; i < missing_out.size(); i++) {
    int m_in = missing_in[i];
    int m_out = missing_out[i];
    out[m_out] = m_in;
    in[m_in] = m_out;
  }
  for (int i = 0; i < k; i++) {
    char x = out[i] + 'a';
    cout << x;
  }
  cout << "\n";
}
bool solveGreater() {
  for (int i = diffPos + 1; i < n; i++) {
    int cs = s[i] - 'a';
    int ca = a[i] - 'a';
    if (out[cs] != -1) {
      if (out[cs] > ca) {
        cout << "YES\n";
        build();
        return true;
      }
      if (out[cs] < ca) {
        return false;
      }
    } else {
      for (int ta = ca + 1; ta < k; ta++) {
        if (in[ta] == -1) {
          in[ta] = cs;
          out[cs] = ta;
          cout << "YES\n";
          build();
          return true;
        }
      }
      if (in[ca] != -1) return false;
      in[ca] = cs;
      out[cs] = ca;
    }
  }
  cout << "YES\n";
  build();
  return true;
}
bool solveLess() {
  for (int i = diffPos + 1; i < n; i++) {
    int cs = s[i] - 'a';
    int cb = b[i] - 'a';
    if (out[cs] != -1) {
      if (out[cs] < cb) {
        cout << "YES\n";
        build();
        return true;
      }
      if (out[cs] > cb) return false;
    } else {
      for (int tb = cb - 1; tb >= 0; tb--) {
        if (in[tb] == -1) {
          in[tb] = cs;
          out[cs] = tb;
          cout << "YES\n";
          build();
          return true;
        }
      }
      if (in[cb] != -1) return false;
      in[cb] = cs;
      out[cs] = cb;
    }
  }
  cout << "YES\n";
  build();
  return true;
}
void solve() {
  n = s.length();
  for (int i = 0; i < k; i++) {
    in[i] = -1;
    out[i] = -1;
  }
  diffPos = -1;
  for (int i = 0; i < n; i++) {
    int cs = s[i] - 'a';
    int ca = a[i] - 'a';
    int cb = b[i] - 'a';
    if (ca < cb) {
      diffPos = i;
      break;
    }
    if (ca > cb) {
      cout << "NO\n";
      return;
    }
    if (out[cs] == -1 && in[ca] == -1) {
      out[cs] = ca;
      in[ca] = cs;
    } else {
      if (out[cs] == ca && in[ca] == cs) {
        continue;
      } else {
        cout << "NO\n";
        return;
      }
    }
  }
  if (diffPos == -1) {
    cout << "YES\n";
    build();
    return;
  }
  int val_a = a[diffPos] - 'a';
  int val_b = b[diffPos] - 'a';
  int val_s = s[diffPos] - 'a';
  if (out[val_s] != -1) {
    if (out[val_s] > val_a && out[val_s] < val_b) {
      cout << "YES\n";
      build();
      return;
    }
    if (out[val_s] < val_a || out[val_s] > val_b) {
      cout << "NO\n";
      return;
    }
    if (out[val_s] == val_a) {
      if (solveGreater() == false) cout << "NO\n";
      return;
    }
    if (out[val_s] == val_b) {
      if (solveLess() == false) cout << "NO\n";
      return;
    }
  } else {
    for (int x = val_a + 1; x < val_b; x++) {
      if (in[x] >= 0) continue;
      out[val_s] = x;
      in[x] = val_s;
      cout << "YES\n";
      build();
      return;
    }
    for (int i = 0; i < k; i++) {
      memo_in[i] = in[i];
      memo_out[i] = out[i];
    }
    if (in[val_b] == -1) {
      in[val_b] = val_s;
      out[val_s] = val_b;
      if (solveLess()) return;
    }
    for (int i = 0; i < k; i++) {
      in[i] = memo_in[i];
      out[i] = memo_out[i];
    }
    if (in[val_a] == -1) {
      in[val_a] = val_s;
      out[val_s] = val_a;
      if (solveGreater()) return;
    }
    cout << "NO\n";
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t > 0) {
    cin >> k;
    cin >> s >> a >> b;
    solve();
    t--;
  }
}
