#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
  t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
  t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "URDL";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int& x, int y, int mod = 998244353) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et(int x = -1) {
  printf("%d\n", x);
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 998244353) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }
char s[1000035], a[1000035], b[1000035];
int p[33], rp[33];
bool calS(int pos) {
  vector<int> tp(30, -1), trp(30, -1);
  for (int(i) = 0; (i) < (int)(k); (i)++) {
    tp[i] = p[i];
    trp[i] = rp[i];
  }
  for (int i = pos; i <= n; i++) {
    int c = s[i] - 'a', t = a[i] - 'a';
    if (tp[c] == -1) {
      for (int j = k - 1; j >= t; j--)
        if (trp[j] == -1) {
          trp[j] = c;
          tp[c] = j;
          break;
        }
      if (tp[c] == -1) return 0;
    }
    assert(tp[c] != -1);
    if (tp[c] < t) return 0;
    if (tp[c] > t) {
      for (int(i) = 0; (i) < (int)(k); (i)++) {
        p[i] = tp[i];
        rp[i] = trp[i];
      }
      return 1;
    }
  }
  for (int(i) = 0; (i) < (int)(k); (i)++) {
    p[i] = tp[i];
    rp[i] = trp[i];
  }
  return 1;
}
bool calB(int pos) {
  vector<int> tp(30, -1), trp(30, -1);
  for (int(i) = 0; (i) < (int)(k); (i)++) {
    tp[i] = p[i];
    trp[i] = rp[i];
  }
  for (int i = pos; i <= n; i++) {
    int c = s[i] - 'a', t = b[i] - 'a';
    if (tp[c] == -1) {
      for (int j = 0; j <= t; j++)
        if (trp[j] == -1) {
          trp[j] = c;
          tp[c] = j;
          break;
        }
      if (tp[c] == -1) return 0;
    }
    assert(tp[c] != -1);
    if (tp[c] > t) return 0;
    if (tp[c] < t) {
      for (int(i) = 0; (i) < (int)(k); (i)++) {
        p[i] = tp[i];
        rp[i] = trp[i];
      }
      return 1;
    }
  }
  for (int(i) = 0; (i) < (int)(k); (i)++) {
    p[i] = tp[i];
    rp[i] = trp[i];
  }
  return 1;
}
void fmain(int tid) {
  scanf("%d", &k);
  for (int(i) = 0; (i) < (int)(k); (i)++) {
    p[i] = -1;
    rp[i] = -1;
  }
  scanf("%s%s%s", s + 1, a + 1, b + 1);
  n = strlen(s + 1);
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    int c = s[i] - 'a', A = a[i] - 'a', B = b[i] - 'a';
    if (A == B) {
      if (p[c] != -1 && p[c] != A) {
        if (!debug) puts("NO");
        return;
      }
      if (rp[A] != -1 && rp[A] != c) {
        if (!debug) puts("NO");
        return;
      }
      p[c] = A;
      rp[A] = c;
    } else {
      if (p[c] != -1) {
        if (p[c] < A || p[c] > B) {
          if (!debug) puts("NO");
          return;
        }
        if (p[c] > A && p[c] < B) break;
        if (p[c] == A) {
          if (calS(i + 1))
            break;
          else {
            if (!debug) puts("NO");
            return;
          }
        } else {
          assert(p[c] == B);
          if (calB(i + 1))
            break;
          else {
            if (!debug) puts("NO");
            return;
          }
        }
      } else {
        bool ok = 0;
        for (int z = A + 1; z < B; z++)
          if (rp[z] == -1) {
            p[c] = z;
            rp[z] = c;
            ok = 1;
            break;
          }
        if (ok) break;
        if (rp[A] == -1) {
          p[c] = A;
          rp[A] = c;
          if (calS(i + 1)) break;
          p[c] = -1;
          rp[A] = -1;
        }
        if (rp[B] == -1) {
          p[c] = B;
          rp[B] = c;
          if (calB(i + 1)) break;
          p[c] = -1;
          rp[B] = -1;
        }
        if (!debug) puts("NO");
        return;
      }
    }
  }
  if (!debug) puts("YES");
  vector<int> rm;
  for (int(j) = 0; (j) < (int)(k); (j)++)
    if (rp[j] == -1) rm.push_back(j);
  for (int(j) = 0; (j) < (int)(k); (j)++)
    if (p[j] == -1) {
      assert(!rm.empty());
      p[j] = rm.back();
      rm.pop_back();
    }
  for (int(j) = 0; (j) < (int)(k); (j)++)
    if (!debug) printf("%c", 'a' + p[j]);
  if (!debug) puts("");
}
int main() {
  int t = 1;
  scanf("%d", &t);
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
