#include <bits/stdc++.h>
char readCharacter;
bool remaining = false;
template <typename T>
bool readInt(T &x);
template <typename T>
bool readString(T &x);
template <typename T>
bool readChar(T &x);
bool readCharArray(char *&x);
template <typename T>
bool readFloat(T &x);
template <typename T>
bool readDouble(T &x);
bool readVar(bool &x);
bool readVar(short int &x);
bool readVar(int &x);
bool readVar(long int &x);
bool readVar(long long int &x);
bool readVar(unsigned short int &x);
bool readVar(unsigned int &x);
bool readVar(unsigned long &x);
bool readVar(unsigned long long &x);
bool readVar(std::string &x);
bool readVar(char &x);
bool readVar(char *&x);
bool readVar(float &x);
bool readVar(double &x);
bool readVar(long double &x);
template <typename T>
void writeInt(T x);
void writeString(std::string x);
void writeChar(char x);
void writeCharArray(char *x);
void writeFloat(float x);
template <typename T>
void writeDouble(T x);
void writeVar(bool x);
void writeVar(short int x);
void writeVar(int x);
void writeVar(long int x);
void writeVar(long long int x);
void writeVar(unsigned short int x);
void writeVar(unsigned int x);
void writeVar(unsigned long x);
void writeVar(unsigned long long x);
void writeVar(char x);
void writeVar(char *x);
void writeVar(std::string x);
void writeVar(float x);
void writeVar(double x);
void writeVar(long double x);
using namespace std;
int x, l, r, k, u[30], res, t;
string s, a, b;
vector<int> g, e;
int main() {
  readVar(t);
  while (t--) {
    readVar(k), readVar(s), readVar(a), readVar(b);
    int n = int(s.size());
    g.clear();
    for (int i = 0; i < k; ++i) {
      u[i] = -1;
      g.push_back(i);
    }
    bool ok = 0, ok1 = 0, ok2 = 0;
    for (int i = 0; i < n; ++i) {
      x = s[i] - 'a';
      l = a[i] - 'a';
      r = b[i] - 'a';
      res = -1;
      if (ok1) l = -1;
      if (ok2) r = k;
      if (u[x] != -1) {
        if (u[x] < l || u[x] > r) {
          ok = 1;
          break;
        }
        if (u[x] > l) ok1 = 1;
        if (u[x] < r) ok2 = 1;
        continue;
      }
      e.clear();
      for (int j = 0; j < int(g.size()); ++j) {
        if (l > g[j] || r < g[j]) continue;
        e.push_back(j);
        if (int(e.size()) == 3) break;
      }
      if (!int(e.size())) {
        ok = 1;
        break;
      }
      if (int(e.size()) == 1) {
        res = e[0];
      }
      if (res == -1)
        for (auto to : e) {
          if (l < g[to] && g[to] < r) {
            res = to;
            break;
          }
        }
      if (res == -1) {
        if (g[e[0]] == l) res = e[0];
        if (g[e[1]] == l) res = e[1];
        if (res == -1) {
          res = e[0];
        }
      }
      u[x] = g[res];
      if (g[res] > l) ok1 = 1;
      if (g[res] < r) ok2 = 1;
      swap(g[res], g[int(g.size()) - 1]);
      g.pop_back();
    }
    if (!ok) {
      writeVar("YES\n");
      for (int i = 0; i < k; ++i) {
        if (u[i] == -1) {
          u[i] = g[int(g.size()) - 1];
          g.pop_back();
        }
        writeVar(char(u[i] + 'a'));
      }
      writeVar('\n');
      continue;
    }
    g.clear();
    for (int i = 0; i < k; ++i) {
      u[i] = -1;
      g.push_back(i);
    }
    ok = 0;
    ok1 = 0;
    ok2 = 0;
    for (int i = 0; i < n; ++i) {
      x = s[i] - 'a';
      l = a[i] - 'a';
      r = b[i] - 'a';
      res = -1;
      if (ok1) l = -1;
      if (ok2) r = k;
      if (u[x] != -1) {
        if (u[x] < l || u[x] > r) {
          ok = 1;
          break;
        }
        if (u[x] > l) ok1 = 1;
        if (u[x] < r) ok2 = 1;
        continue;
      }
      e.clear();
      for (int j = 0; j < int(g.size()); ++j) {
        if (l > g[j] || r < g[j]) continue;
        e.push_back(j);
        if (int(e.size()) == 3) break;
      }
      if (!int(e.size())) {
        ok = 1;
        break;
      }
      if (int(e.size()) == 1) {
        res = e[0];
      }
      if (res == -1)
        for (auto to : e) {
          if (l < g[to] && g[to] < r) {
            res = to;
            break;
          }
        }
      if (res == -1) {
        if (g[e[0]] == r) res = e[0];
        if (g[e[1]] == r) res = e[1];
        if (res == -1) {
          res = e[0];
        }
      }
      u[x] = g[res];
      if (g[res] > l) ok1 = 1;
      if (g[res] < r) ok2 = 1;
      swap(g[res], g[int(g.size()) - 1]);
      g.pop_back();
    }
    if (!ok) {
      writeVar("YES\n");
      for (int i = 0; i < k; ++i) {
        if (u[i] == -1) {
          u[i] = g[int(g.size()) - 1];
          g.pop_back();
        }
        writeVar(char(u[i] + 'a'));
      }
      writeVar('\n');
      continue;
    }
    writeVar("NO\n");
  }
  return 0;
}
template <typename T>
bool readInt(T &x) {
  x = 0;
  T sig = 1;
  if (!remaining)
    readCharacter = getchar(), remaining = true;
  else
    remaining = false;
  while (!isdigit(readCharacter) && readCharacter != EOF)
    sig = (readCharacter == '-' ? -sig : sig), readCharacter = getchar();
  if (readCharacter == EOF) return remaining = false, false;
  while (isdigit(readCharacter) && readCharacter != EOF)
    x = x * 10 + readCharacter - '0', readCharacter = getchar();
  x *= sig;
  return true;
}
template <typename T>
bool readString(T &x) {
  x = "";
  if (!remaining)
    readCharacter = getchar(), remaining = true;
  else
    remaining = false;
  while (
      (readCharacter == '\n' || readCharacter == '\t' || readCharacter == ' '))
    readCharacter = getchar();
  if (readCharacter == EOF) return remaining = false, false;
  while ((readCharacter != '\n' && readCharacter != '\t' &&
          readCharacter != ' ' && readCharacter != EOF))
    x += readCharacter, readCharacter = getchar();
  return true;
}
template <typename T>
bool readChar(T &x) {
  if (!remaining)
    readCharacter = getchar();
  else
    remaining = false;
  if (readCharacter == EOF) return remaining = false, false;
  while (
      (readCharacter == '\n' || readCharacter == '\t' || readCharacter == ' '))
    readCharacter = getchar();
  remaining = false;
  x = readCharacter;
  return true;
}
bool readCharArray(char *&x) {
  std::string y;
  if (readString(y) == false) return false;
  x = new char[(int)y.size() + 1];
  strcpy(x, y.c_str());
  return true;
}
template <typename T>
bool readFloat(T &x) {
  return (scanf("%f", &x) != EOF);
}
template <typename T>
bool readDouble(T &x) {
  double y;
  if (scanf("%lf", &y) == EOF) return false;
  x = y;
  return true;
}
bool readVar(bool &x) {
  int aux;
  bool ret = readInt(aux);
  x = (aux != 0);
  return ret;
}
bool readVar(short int &x) { return readInt(x); }
bool readVar(int &x) { return readInt(x); }
bool readVar(long int &x) { return readInt(x); }
bool readVar(long long int &x) { return readInt(x); }
bool readVar(unsigned short int &x) { return readInt(x); }
bool readVar(unsigned int &x) { return readInt(x); }
bool readVar(unsigned long &x) { return readInt(x); }
bool readVar(unsigned long long &x) { return readInt(x); }
bool readVar(std::string &x) { return readString(x); }
bool readVar(char &x) { return readChar(x); }
bool readVar(char *&x) { return readCharArray(x); }
bool readVar(float &x) { return readFloat(x); }
bool readVar(double &x) { return readDouble(x); }
bool readVar(long double &x) { return readDouble(x); }
template <typename T>
void writeInt(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  char writeBuffer[20], *writePtr = writeBuffer;
  do {
    *writePtr++ = '0' + x % 10;
    x /= 10;
  } while (x);
  do {
    putchar(*--writePtr);
  } while (writePtr > writeBuffer);
}
void writeChar(char x) { putchar(x); }
void writeCharArray(char *x) {
  while (*x != '\0') putchar(*x++);
}
void writeString(std::string x) {
  for (char c : x) putchar(c);
}
void writeFloat(float x) { printf("%f", x); }
template <typename T>
void writeDouble(T x) {
  printf("%lf", (double)x);
}
void writeVar(bool x) { writeInt(x); }
void writeVar(short int x) { writeInt(x); }
void writeVar(int x) { writeInt(x); }
void writeVar(long int x) { writeInt(x); }
void writeVar(long long int x) { writeInt(x); }
void writeVar(unsigned short int x) { writeInt(x); }
void writeVar(unsigned int x) { writeInt(x); }
void writeVar(unsigned long x) { writeInt(x); }
void writeVar(unsigned long long x) { writeInt(x); }
void writeVar(std::string x) { writeString(x); }
void writeVar(char x) { writeChar(x); }
void writeVar(char *x) { writeCharArray(x); }
void writeVar(float x) { writeFloat(x); }
void writeVar(double x) { writeDouble(x); }
void writeVar(long double x) { writeDouble(x); }
