func_code_string: #include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0;     bool t = false;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) t = true, ch = getchar();     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch - 48, ch = getchar();     return t ? -x : x;   }   int s[1010000], a[1010000], b[1010000], n, k;   char ch[1010000];   bool vis[1010000];   int eql[1010000];   void output() {     for (int i = 1; i <= k; ++i)       if (!eql[i])         for (int j = 1; j <= k; ++j)           if (!vis[j]) {             eql[i] = j;             vis[j] = true;             break;           }     for (int i = 1; i <= k; ++i) putchar(eql[i] + 96);     puts(  );   }   void clear() {     for (int i = 1; i <= k; ++i) eql[i] = 0, vis[i] = false;   }   int main() {     int T = read();     while (T--) {       k = read();       scanf( %s , ch + 1);       n = strlen(ch + 1);       for (int i = 1; i <= n; ++i) s[i] = ch[i] - 96;       scanf( %s , ch + 1);       for (int i = 1; i <= n; ++i) a[i] = ch[i] - 96 - (i == n);       scanf( %s , ch + 1);       for (int i = 1; i <= n; ++i) b[i] = ch[i] - 96;       clear();       int p = -1;       for (int i = 1; i <= n; ++i) {         if (i > 1) {           if (eql[s[i - 1]] && eql[s[i - 1]] != a[i - 1]) break;           if (!eql[s[i - 1]] && vis[a[i - 1]]) break;           eql[s[i - 1]] = a[i - 1];           vis[a[i - 1]] = true;         }         if (eql[s[i]])           if (eql[s[i]] > a[i]) p = i;         if (!eql[s[i]])           for (int j = a[i] + 1; j <= k; ++j)             if (!vis[j]) {               p = i;               break;             }       }       if (p == -1)         puts( NO );       else {         clear();         for (int i = 1; i < p; ++i) eql[s[i]] = a[i], vis[a[i]] = true;         if (!eql[s[p]])           for (int i = a[p] + 1; i <= k; ++i)             if (!vis[i]) {               eql[s[p]] = i, vis[i] = true;               break;             }         for (int i = p + 1; i <= n; ++i)           if (!eql[s[i]])             for (int j = 1; j <= k; ++j)               if (!vis[j]) {                 eql[s[i]] = j;                 vis[j] = true;                 break;               }         for (int i = 1; i <= n; ++i) s[i] = eql[s[i]];         bool chk = true;         for (int i = 1; i <= n; ++i)           if (s[i] > b[i]) {             puts( NO );             chk = false;             break;           } else if (s[i] < b[i]) {             puts( YES );             output();             chk = false;             break;           }         if (chk) puts( YES ), output();       }     }   }   