#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 5;
const int inf = (int)1e9 + 7;
int t;
int has[26];
vector<int> to(26, -1);
vector<int> last(26, -2);
string s;
void solve() {
  int k;
  string a, b;
  cin >> k >> s >> a >> b;
  for (int i = 0; i < 26; ++i) {
    to[i] = -1;
    last[i] = -2;
    has[i] = 0;
  }
  int bad = 0;
  for (int i = 0; i < (int)((s).size()); ++i) {
    int f = s[i] - 'a';
    int s = a[i] - 'a';
    if (to[f] == -1) {
      int g = -1;
      for (int j = s + 1; j < k; ++j) {
        if (!has[j]) {
          g = j;
          break;
        }
      }
      if (g != -1) {
        last = to;
        last[f] = g;
      }
    } else {
      if (to[f] < s) {
        bad = 1;
        break;
      }
      if (to[f] == s) continue;
      last = to;
    }
    if (to[f] != -1 && to[f] != s) {
      bad = 1;
      break;
    }
    if (to[f] == s) continue;
    if (has[s] != 0) {
      bad = 1;
      break;
    }
    to[f] = s;
    has[s] = 1;
  }
  if (!bad) {
    last = to;
  }
  if (last[0] == -2) {
    cout << "NO\n";
    return;
  }
  for (int j = 0; j < k; ++j) {
    has[j] = 0;
  }
  for (int j = 0; j < k; ++j) {
    if (last[j] != -1) has[last[j]] = 1;
  }
  bad = 0;
  for (int j = 0; j < (int)((s).size()); ++j) {
    if (last[s[j] - 'a'] == -1) {
      for (int l = 0; l < k; ++l) {
        if (!has[l]) {
          has[l] = 1;
          last[s[j] - 'a'] = l;
          break;
        }
      }
    }
    s[j] = char(last[s[j] - 'a'] + 'a');
  }
  for (int j = 0; j < k; ++j) {
    if (last[j] == -1) {
      for (int s = 0; s < k; ++s) {
        if (!has[s]) {
          has[s] = 1;
          last[j] = s;
          break;
        }
      }
    }
  }
  if (s <= b) {
    cout << "YES\n";
    for (int j = 0; j < k; ++j) {
      cout << char(last[j] + 'a');
    }
    cout << "\n";
  } else {
    cout << "NO\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
