#include <bits/stdc++.h>
using namespace std;
double START_TIME;
void exit() { exit(0); }
template <typename A, typename B>
ostream& operator<<(ostream& os, pair<A, B> p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
  for (int i = 0; i <= (int)v.size() - 1; i++) {
    os << v[i] << " ";
  }
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> t) {
  for (auto z : t) {
    os << z << " ";
  }
  return os;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, map<T1, T2> t) {
  cerr << endl;
  for (auto z : t) {
    os << "\t" << z.first << " -> " << z.second << endl;
  }
  return os;
}
const int MAX = 1000 * 1000 + 41;
int n;
int s[MAX];
int a[MAX];
int b[MAX];
int k;
char str[MAX];
char ans[2][2][2][26];
bool can[2][2][2];
bool used[2][2][2][26];
void ok(vector<int> ans) {
  printf("YES\n");
  for (int i = 0; i <= (int)ans.size() - 1; i++) {
    char c = (char)(ans[i] + 'a');
    printf("%c", c);
  }
  printf("\n");
}
void solve() {
  memset(ans, -1, sizeof(ans));
  memset(can, false, sizeof(can));
  can[0][0][0] = 1;
  memset(used, false, sizeof(used));
  for (int i = 1; i <= n; i++) {
    memset(ans[1], -1, sizeof(ans[1]));
    memset(can[1], false, sizeof(can[0]));
    memset(used[1], false, sizeof(used[0]));
    for (int f1 = 1; f1 >= 0; f1--) {
      for (int f2 = 1; f2 >= 0; f2--) {
        if (!can[0][f1][f2]) continue;
        int ch = s[i];
        for (int o = 0; o <= k - 1; o++) {
          if (used[0][f1][f2][o] && ans[0][f1][f2][ch] != o) {
            continue;
          }
          if (ans[0][f1][f2][ch] != -1 && ans[0][f1][f2][ch] != o) continue;
          if (!f1 && o < a[i]) continue;
          if (!f2 && o > b[i]) continue;
          int nf1 = f1;
          if (o > a[i]) nf1 = 1;
          int nf2 = f2;
          if (o < b[i]) nf2 = 1;
          if (nf1 && nf2) {
            vector<int> ans(k);
            vector<int> vp, vv;
            ::ans[0][f1][f2][ch] = o;
            used[0][f1][f2][o] = 1;
            for (int x = 0; x < k; x++) {
              ans[x] = ::ans[0][f1][f2][x];
              if (ans[x] == -1) {
                vp.push_back(x);
              }
              if (!used[0][f1][f2][x]) {
                vv.push_back(x);
              }
            }
            assert((int)vp.size() == (int)vv.size());
            for (int x = 0; x < (int)vp.size(); x++) {
              ans[vp[x]] = vv[x];
            }
            ok(ans);
            return;
          }
          can[1][nf1][nf2] = 1;
          memcpy(ans[1][nf1][nf2], ans[0][f1][f2], sizeof(ans[1][nf1][nf2]));
          memcpy(used[1][nf1][nf2], used[0][f1][f2], sizeof(used[1][nf1][nf2]));
          used[1][nf1][nf2][o] = 1;
          ans[1][nf1][nf2][ch] = o;
        }
      }
    }
    for (int f1 = 0; f1 <= 1; f1++) {
      for (int f2 = 0; f2 <= 1; f2++) {
        memcpy(ans[0], ans[1], sizeof(ans[0]));
        memcpy(used[0], used[1], sizeof(used[0]));
        memcpy(can[0], can[1], sizeof(can[0]));
      }
    }
  }
  for (int f1 = 0; f1 <= 1; f1++) {
    for (int f2 = 0; f2 <= 1; f2++) {
      if (can[0][f1][f2]) {
        vector<int> ans(k);
        vector<int> vp, vv;
        for (int x = 0; x < k; x++) {
          ans[x] = ::ans[0][f1][f2][x];
          if (ans[x] == -1) {
            vp.push_back(x);
          }
          if (!used[0][f1][f2][x]) {
            vv.push_back(x);
          }
        }
        assert((int)vp.size() == (int)vv.size());
        for (int x = 0; x < (int)vp.size(); x++) {
          ans[vp[x]] = vv[x];
        }
        ok(ans);
        return;
      }
    }
  }
  printf("NO\n");
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &k);
    scanf("%s", str);
    n = strlen(str);
    for (int i = 1; i <= n; i++) {
      s[i] = str[i - 1] - 'a';
    }
    scanf("%s", str);
    for (int i = 1; i <= n; i++) {
      a[i] = str[i - 1] - 'a';
    }
    scanf("%s", str);
    for (int i = 1; i <= n; i++) {
      b[i] = str[i - 1] - 'a';
    }
    solve();
  }
  exit();
  return 0;
}
