#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 6;
int mask[26], back[26];
char s[MAX], a[MAX], b[MAX];
int n, k;
bool found;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &k);
    scanf("%s", s);
    scanf("%s", a);
    scanf("%s", b);
    n = strlen(s);
    memset(mask, -1, sizeof mask);
    memset(back, -1, sizeof back);
    bool ok = false;
    for (int i = int(0); i < int(n); i++) {
      int val = s[i] - 'a';
      int aval = a[i] - 'a';
      int bval = b[i] - 'a';
      if (mask[val] != -1) {
        int rval = mask[val];
        if (rval < aval || bval < rval) {
          break;
        }
        if (aval < rval && rval < bval) {
          ok = true;
          break;
        }
        if (rval < bval) {
          for (int j = int(i + 1); j < int(n); j++) {
            int mval = s[j] - 'a';
            if (mask[mval] == -1) {
              for (int f = int(k - 1); f >= int(0); f--) {
                if (back[f] == -1) {
                  mask[mval] = f;
                  back[f] = mval;
                  break;
                }
              }
            }
          }
          for (int j = int(0); j < int(n); j++) {
            int taval = a[j] - 'a';
            int mval = s[j] - 'a';
            int tmval = mask[mval];
            if (taval < tmval) {
              ok = true;
            }
            if (taval != tmval) {
              break;
            }
            if (j == n - 1) {
              ok = true;
            }
          }
          break;
        }
        if (aval < rval) {
          for (int j = int(i + 1); j < int(n); j++) {
            int mval = s[j] - 'a';
            if (mask[mval] == -1) {
              for (int f = int(0); f < int(k); f++) {
                if (back[f] == -1) {
                  mask[mval] = f;
                  back[f] = mval;
                  break;
                }
              }
            }
          }
          for (int j = int(0); j < int(n); j++) {
            int tbval = b[j] - 'a';
            int mval = s[j] - 'a';
            int tmval = mask[mval];
            if (tbval > tmval) {
              ok = true;
            }
            if (tbval != tmval) {
              break;
            }
            if (j == n - 1) {
              ok = true;
            }
          }
          break;
        }
      } else {
        if (aval == bval) {
          if (back[aval] != -1) {
            break;
          }
          mask[val] = aval;
          back[aval] = val;
        } else {
          int who = -1;
          for (int j = int(aval + 1); j < int(bval); j++) {
            if (back[j] == -1) {
              who = j;
              break;
            }
          }
          if (who != -1) {
            mask[val] = who;
            back[who] = val;
            ok = true;
            break;
          } else {
            if (back[aval] == -1) {
              mask[val] = aval;
              back[aval] = mask[val];
              vector<int> rollback, br;
              for (int j = int(i + 1); j < int(n); j++) {
                int mval = s[j] - 'a';
                if (mask[mval] == -1) {
                  for (int f = int(k - 1); f >= int(0); f--) {
                    if (back[f] == -1) {
                      mask[mval] = f;
                      back[f] = mval;
                      rollback.push_back(mval);
                      br.push_back(f);
                      break;
                    }
                  }
                }
              }
              for (int j = int(0); j < int(n); j++) {
                int taval = a[j] - 'a';
                int mval = s[j] - 'a';
                int tmval = mask[mval];
                if (taval < tmval) {
                  ok = true;
                }
                if (taval != tmval) {
                  break;
                }
                if (j == n - 1) {
                  ok = true;
                }
              }
              if (ok) {
                break;
              }
              for (auto &each : rollback) {
                mask[each] = -1;
              }
              for (auto &each : br) {
                back[each] = -1;
              }
              mask[val] = back[aval] = -1;
            }
            if (back[bval] == -1) {
              mask[val] = bval;
              back[bval] = mask[val];
              for (int j = int(i + 1); j < int(n); j++) {
                int mval = s[j] - 'a';
                if (mask[mval] == -1) {
                  for (int f = int(0); f < int(k); f++) {
                    if (back[f] == -1) {
                      mask[mval] = f;
                      back[f] = mval;
                      break;
                    }
                  }
                }
              }
              for (int j = int(0); j < int(n); j++) {
                int tbval = b[j] - 'a';
                int mval = s[j] - 'a';
                int tmval = mask[mval];
                if (tbval > tmval) {
                  ok = true;
                }
                if (tbval != tmval) {
                  break;
                }
                if (j == n - 1) {
                  ok = true;
                }
              }
            }
            break;
          }
        }
      }
      if (i == n - 1) {
        ok = true;
      }
    }
    if (ok) {
      puts("YES");
      for (int i = int(0); i < int(k); i++) {
        if (mask[i] == -1) {
          for (int j = int(0); j < int(k); j++) {
            if (back[j] == -1) {
              mask[i] = j;
              back[j] = i;
              break;
            }
          }
        }
      }
      for (int i = int(0); i < int(k); i++) {
        printf("%c", (char)(mask[i] + 'a'));
      }
      puts("");
    } else {
      puts("NO");
    }
  }
  return 0;
}
