#include <bits/stdc++.h>
using namespace std;
int len, n, m, ans[1000], bo[1000], t;
char s[1000005], a[1000005], b[1000005];
int dfs(int x, int bo1, int bo2) {
  if (x > len) {
    return 1;
  }
  int p = s[x] - 96, l, r;
  if (bo1) {
    l = a[x] - 96;
  } else {
    l = 1;
  }
  if (bo2) {
    r = b[x] - 96;
  } else {
    r = m;
  }
  if (ans[p]) {
    if (ans[p] < l || ans[p] > r) {
      return 0;
    }
    return dfs(x + 1, bo1 & (ans[p] == l), bo2 & (ans[p] == r));
  } else {
    for (int i = l; i <= r; ++i) {
      if (!bo[i]) {
        bo[i] = 1;
        ans[p] = i;
        if (dfs(x + 1, bo1 & (i == l), bo2 & (i == r))) {
          return 1;
        }
        bo[i] = 0;
        ans[p] = 0;
      }
    }
    return 0;
  }
}
int main() {
  long long T;
  cin >> T;
  while (T--) {
    cin >> m;
    scanf("%s%s%s", s + 1, a + 1, b + 1);
    len = strlen(s + 1);
    for (int i = 1; i <= m; ++i) {
      ans[i] = 0;
      bo[i] = 0;
    }
    if (dfs(1, 1, 1)) {
      puts("YES");
      for (int i = 1, j = 1; i <= m; ++i) {
        if (!ans[i]) {
          while (bo[j]) {
            ++j;
          }
          ans[i] = j;
          bo[j] = 1;
        }
      }
      for (int i = 1; i <= m; ++i) {
        cout << char(96 + ans[i]);
      }
      puts("");
    } else {
      puts("NO");
    }
  }
  return 0;
}
