#include <bits/stdc++.h>
using namespace std;
const int MAX = 1 << 20, A = 26;
int n, k;
int kamo[A], odakle[A];
char s[MAX], a[MAX], b[MAX];
int DEB = 0;
void dopuni() {
  for (int i = 0; i < k; i++) {
    if (kamo[i] != -1) continue;
    for (int j = 0; j < k; j++) {
      if (odakle[j] == -1) {
        kamo[i] = j;
        odakle[j] = i;
        break;
      }
    }
  }
}
void dopuni_min(int ind) {
  for (int i = (ind); i < (n); i++) {
    int c = s[i] - 'a';
    if (kamo[c] == -1) {
      int mn = -1;
      for (int j = 0; j < k; j++) {
        if (odakle[j] == -1) {
          mn = j;
          break;
        }
      }
      assert(mn != -1);
      kamo[c] = mn;
      odakle[mn] = c;
    }
  }
  dopuni();
}
void dopuni_max(int ind) {
  for (int i = (ind); i < (n); i++) {
    int c = s[i] - 'a';
    if (kamo[c] == -1) {
      int mx = -1;
      for (int j = k - 1; j >= 0; j--) {
        if (odakle[j] == -1) {
          mx = j;
          break;
        }
      }
      assert(mx != -1);
      kamo[c] = mx;
      odakle[mx] = c;
    }
  }
  dopuni();
}
void trans(char *nov) {
  for (int i = 0; i < n; i++) nov[i] = (char)('a' + kamo[s[i] - 'a']);
  nov[n] = 0;
}
int done = 0;
char kraj[MAX];
void check() {
  if (done) return;
  trans(kraj);
  if (strcmp(kraj, a) >= 0 && strcmp(kraj, b) <= 0) {
    done = 1;
    printf("YES\n");
    for (int j = 0; j < k; j++) printf("%c", (char)(kamo[j] + 'a'));
    printf("\n");
  }
}
void go() {
  for (int st = 0; st < 2; st++) {
    memset(kamo, -1, sizeof kamo);
    memset(odakle, -1, sizeof odakle);
    int ck = 0;
    for (int i = 0; i < n; i++) {
      if (ck) break;
      int c = s[i] - 'a';
      if (a[i] != b[i]) {
        if (kamo[c] != -1) {
          if (!st) {
            dopuni_max(i + 1);
            ck = 1;
            check();
            break;
          } else {
            dopuni_min(i + 1);
            ck = 1;
            check();
            break;
          }
        }
        for (int j = 0; j < k; j++) {
          if (odakle[j] == -1) {
            if (j > a[i] - 'a' && j < b[i] - 'a') {
              kamo[c] = j;
              odakle[j] = c;
              dopuni();
              check();
              ck = 1;
              break;
            }
          }
        }
        if (ck) break;
        if (!st && odakle[a[i] - 'a'] == -1) {
          kamo[c] = a[i] - 'a';
          odakle[a[i] - 'a'] = c;
          dopuni_max(i + 1);
          check();
          ck = 1;
        } else if (st && odakle[b[i] - 'a'] == -1) {
          kamo[c] = b[i] - 'a';
          odakle[b[i] - 'a'] = c;
          dopuni_min(i + 1);
          check();
          ck = 1;
        }
      } else {
        if (kamo[c] == -1 && odakle[a[i] - 'a'] == -1) {
          kamo[c] = a[i] - 'a';
          odakle[a[i] - 'a'] = c;
        }
      }
    }
    dopuni();
    check();
  }
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    done = 0;
    scanf("%d", &k);
    scanf(" %s %s %s", s, a, b);
    n = (int)strlen(s);
    go();
    if (!done) printf("NO\n");
  }
  return 0;
}
