#include <bits/stdc++.h>
using namespace std;
string trans(vector<char> bridge, string s) {
  for (auto &x : s) {
    x = bridge[x - 'a'];
  }
  return s;
}
void solve() {
  long long k;
  string s, a, b;
  cin >> k >> s >> a >> b;
  vector<char> ans(k, '-'), rev_ans(k, '-');
  for (long long i = 0; i < s.size(); i++) {
    if (ans[s[i] - 'a'] == '-') {
      if (rev_ans[b[i] - 'a'] != '-') {
        for (long long curr = b[i] - 'a'; curr >= 0; curr--) {
          if (rev_ans[curr] == '-') {
            rev_ans[curr] = s[i];
            ans[s[i] - 'a'] = curr + 'a';
            break;
          }
        }
        long long r = k - 1;
        for (long long j = i + 1; j < s.size(); j++) {
          if (ans[s[j] - 'a'] == '-') {
            while (rev_ans[r] != '-') {
              r--;
            }
            ans[s[j] - 'a'] = r + 'a';
            rev_ans[r] = s[j];
          }
        }
        break;
      }
      vector<char> ans2 = ans, rev_ans2 = rev_ans;
      ans2[s[i] - 'a'] = b[i];
      rev_ans2[b[i] - 'a'] = s[i];
      for (long long j = i + 1; j < s.size(); j++) {
        if (ans2[s[j] - 'a'] == '-') {
          for (long long curr = 0; curr < k; curr++) {
            if (rev_ans2[curr] == '-') {
              rev_ans2[curr] = s[j];
              ans2[s[j] - 'a'] = curr + 'a';
              break;
            }
          }
        }
      }
      if (trans(ans2, s) <= b) {
        ans[s[i] - 'a'] = b[i];
        rev_ans[b[i] - 'a'] = s[i];
      } else {
        for (long long curr = b[i] - 'a' - 1; curr >= 0; curr--) {
          if (rev_ans[curr] == '-') {
            rev_ans[curr] = s[i];
            ans[s[i] - 'a'] = curr + 'a';
            break;
          }
        }
        long long r = k - 1;
        for (long long j = i + 1; j < s.size(); j++) {
          if (ans[s[j] - 'a'] == '-') {
            while (rev_ans[r] != '-') {
              r--;
            }
            ans[s[j] - 'a'] = r + 'a';
            rev_ans[r] = s[j];
          }
        }
        break;
      }
    } else if (ans[s[i] - 'a'] < b[i]) {
      long long r = k - 1;
      for (long long j = i + 1; j < s.size(); j++) {
        if (ans[s[j] - 'a'] == '-') {
          while (rev_ans[r] != '-') {
            r--;
          }
          ans[s[j] - 'a'] = r + 'a';
          rev_ans[r] = s[j];
        }
      }
      break;
    }
  }
  for (auto &x : ans) {
    if (x == '-') {
      for (long long curr = 0; curr < k; curr++) {
        if (rev_ans[curr] == '-') {
          rev_ans[curr] = 'a';
          x = curr + 'a';
          break;
        }
      }
    }
  }
  s = trans(ans, s);
  if (s >= a && s <= b) {
    cout << "YES\n";
    for (auto x : ans) {
      cout << x;
    }
  } else {
    cout << "NO";
  }
  cout << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
