#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  for (int test = 0; test < t; ++test) {
    string s, a, b;
    int k;
    cin >> k;
    cin >> s >> a >> b;
    vector<char> ans(k);
    vector<short int> used(k);
    int n = s.size();
    bool isOk = true;
    for (int i = 0; i < n; ++i) {
      if (a[i] == b[i]) {
        if (ans[s[i] - 'a'] != 0 && ans[s[i] - 'a'] != a[i]) {
          isOk = false;
          break;
        }
        if (ans[s[i] - 'a'] == 0 && used[a[i] - 'a']) {
          isOk = false;
          break;
        }
        ans[s[i] - 'a'] = a[i];
        used[a[i] - 'a'] = 1;
      } else {
        if (a[i] > b[i]) {
          isOk = false;
          break;
        } else {
          if (ans[s[i] - 'a'] != 0) {
            if (ans[s[i] - 'a'] < a[i] || ans[s[i] - 'a'] > b[i]) {
              isOk = false;
              break;
            }
            if (ans[s[i] - 'a'] > a[i] && ans[s[i] - 'a'] < b[i]) {
              break;
            }
          } else {
            for (int j = a[i] + 1; j < b[i]; ++j) {
              if (!used[j - 'a']) {
                ans[s[i] - 'a'] = j;
                used[j - 'a'] = 1;
                break;
              }
            }
            if (ans[s[i] - 'a'] != 0) {
              break;
            }
          }
          if (ans[s[i] - 'a'] == a[i]) {
            for (int j = i; j < n; ++j) {
              if (ans[s[j] - 'a'] != 0) {
                if (ans[s[j] - 'a'] < a[j]) {
                  isOk = false;
                  break;
                } else if (ans[s[j] - 'a'] > a[j]) {
                  break;
                }
              } else {
                for (int z = a[j] - 'a' + 1; z < k; ++z) {
                  if (!used[z]) {
                    used[z] = 1;
                    ans[s[j] - 'a'] = z + 'a';
                    break;
                  }
                }
                if (ans[s[j] - 'a'] != 0) {
                  break;
                }
                if (!used[a[j] - 'a']) {
                  ans[s[j] - 'a'] = a[j];
                  used[a[j] - 'a'] = 1;
                } else {
                  isOk = false;
                  break;
                }
              }
            }
          } else if (ans[s[i] - 'a'] == b[i]) {
            for (int j = i; j < n; ++j) {
              if (ans[s[j] - 'a'] != 0) {
                if (ans[s[j] - 'a'] > b[j]) {
                  isOk = false;
                  break;
                } else if (ans[s[j] - 'a'] < b[j]) {
                  break;
                }
              } else {
                for (int z = 0; z < b[j] - 'a'; ++z) {
                  if (!used[z]) {
                    used[z] = 1;
                    ans[s[j] - 'a'] = z + 'a';
                    break;
                  }
                }
                if (ans[s[j] - 'a'] != 0) {
                  break;
                }
                if (!used[b[j] - 'a']) {
                  ans[s[j] - 'a'] = b[j];
                  used[b[j] - 'a'] = 1;
                } else {
                  isOk = false;
                  break;
                }
              }
            }
          } else if (ans[s[i] - 'a'] == 0) {
            auto u1 = used;
            auto a1 = ans;
            if (!used[a[i] - 'a']) {
              ans[s[i] - 'a'] = a[i];
              used[a[i] - 'a'] = 1;
              for (int j = i; j < n; ++j) {
                if (ans[s[j] - 'a'] != 0) {
                  if (ans[s[j] - 'a'] < a[j]) {
                    isOk = false;
                    break;
                  } else if (ans[s[j] - 'a'] > a[j]) {
                    break;
                  }
                } else {
                  for (int z = a[j] - 'a' + 1; z < k; ++z) {
                    if (!used[z]) {
                      used[z] = 1;
                      ans[s[j] - 'a'] = z + 'a';
                      break;
                    }
                  }
                  if (ans[s[j] - 'a'] != 0) {
                    break;
                  }
                  if (!used[a[j] - 'a']) {
                    ans[s[j] - 'a'] = a[j];
                    used[a[j] - 'a'] = 1;
                  } else {
                    isOk = false;
                    break;
                  }
                }
              }
            } else {
              isOk = false;
            }
            if (isOk) {
              break;
            }
            isOk = true;
            ans = a1;
            used = u1;
            if (used[b[i] - 'a']) {
              isOk = false;
              break;
            }
            ans[s[i] - 'a'] = b[i];
            used[b[i] - 'a'] = 1;
            for (int j = i; j < n; ++j) {
              if (ans[s[j] - 'a'] != 0) {
                if (ans[s[j] - 'a'] > b[j]) {
                  isOk = false;
                  break;
                } else if (ans[s[j] - 'a'] < b[j]) {
                  break;
                }
              } else {
                for (int z = 0; z < b[j] - 'a'; ++z) {
                  if (!used[z]) {
                    used[z] = 1;
                    ans[s[j] - 'a'] = z + 'a';
                    break;
                  }
                }
                if (ans[s[j] - 'a'] != 0) {
                  break;
                }
                if (!used[b[j] - 'a']) {
                  ans[s[j] - 'a'] = b[j];
                  used[b[j] - 'a'] = 1;
                } else {
                  isOk = false;
                  break;
                }
              }
            }
          }
          break;
        }
      }
    }
    if (isOk) {
      int cur = 0;
      cout << "YES\n";
      for (int i = 0; i < k; ++i) {
        if (ans[i] == 0) {
          while (used[cur]) {
            ++cur;
          }
          ans[i] = cur + 'a';
          used[cur] = 1;
        }
        cout << ans[i];
      }
      cout << "\n";
    } else {
      cout << "NO\n";
    }
  }
  return 0;
}
