#include <iostream>
#include <cstdio>
#include <set>
#include <string>
#include <map>
#include <cstring>
#include <queue>
#include <bitset>

using namespace std;

#define il inline
#define Rint register int
#define pr pair<int,int>
#define read(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
#define maxN 1000005
//#define debug
typedef long long ll;
il int qr(){Rint ret=0,f=1;register char ch = getchar();while(!isdigit(ch)) f=ch=='-'?-1:1,ch=getchar();while(isdigit(ch)) ret=ret*10+ch-'0',ch=getchar();return ret*f;}
int T,N;
string t;
int fir[maxN],nxt[maxN<<3],ver[maxN<<3],tot;
int col[maxN],iid;
//bitset <maxN<<1> vis;
int vis[maxN<<1];
queue <pr> emp,q;
int max_use_fir;
#define nullptr NULL
void lread(int u,int v){
    max_use_fir = max(max_use_fir,u);
    nxt[++tot] = fir[u];
    fir[u] = tot;
    ver[tot] = v;
}
struct trie{
    struct node{
        int val,id;
        bool use;
        node *fa;
        node *son[30];
        #ifdef debug
        string str;
        #endif // debug
    }t[maxN];
    int top,id;
    node *root;
    node *add_node(node *x,int val){
        x->son[val] = &(t[++top]);
        t[top].fa = x;
        return &t[top];
    }
    node *getson(node *x,int val){
        if(x->son[val] != NULL){
            return x->son[val];
        }else return add_node(x,val);
    }
    void build(string a){
        node *ptr = root;
        for(register unsigned i = 0;i<a.length();++i){
            ptr = getson(ptr,(int)(a[i]-'a'));
        }
    }
    #ifdef debug
    void run_similar(node *fptr,node *sptr,string fword,string rword){
    #endif // debug
    #ifndef debug
    void run_similar(node *fptr,node *sptr/*,string fword,string rword*/){
    #endif // debug
        if(sptr != root){
            if(!fptr->id) fptr -> id = ++id;
            if(!sptr->id) sptr -> id = ++id;
            fptr->use = 1,sptr->use = 1;
            lread(fptr->id,sptr->id);
            lread(sptr->id,fptr->id);
            #ifdef debug
            cout << fword << ' ' << rword << endl;
            cout << sptr->id << ' ' << fptr->id << endl;
            #endif // debug
        }
        node *tfptr,*tsptr;
        for(Rint i = 0;i<26;++i){
            if(fptr->son[i] == nullptr || sptr->son[i] == nullptr) continue;
            tfptr = fptr->son[i],tsptr = sptr->son[i];
            #ifndef debug
            run_similar(tfptr,tsptr);
            #endif // debug
            #ifdef debug
            run_similar(tfptr,tsptr,fword+(char)(i+'a'),rword+(char)(i+'a'));
            #endif // debug
        }
    }
    void get(){
        #ifdef debug
        string str;
        #endif // debug
        node *fptr,*sptr;
        fptr = sptr = root;
        for(Rint i = 0;i<26;++i){
            fptr = root;
            if(fptr -> son[i] == nullptr) continue;
            #ifdef debug
            str = (char)(i+'a');
            #endif // debug
            fptr = fptr -> son[i];
            #ifdef debug
            run_similar(fptr,sptr,str,"");
            #endif // debug
            #ifndef debug
            run_similar(fptr,sptr/*,str,""*/);
            #endif // debug
        }
        for(Rint i = 1;i<=top;++i){
            if(!t[i].use){
                if(!t[i].id) t[i].id = ++id;
                lread(t[i].id,t[i].id);
            }
        }
    }
    void clear(){
        memset(t,0,(top+2)*sizeof(t[0]));
        top = 0;id = 0;
        root = &t[0];
    }
    trie(){
        t[0].fa = nullptr;
        root = &t[0];
    }
}a;
int f[2][maxN];
int tree_DP(int u){
    f[0][u] = 0;
    f[1][u] = 1;
    vis[u] = 1;
    for(Rint i = fir[u];i;i=nxt[i]){
        if(vis[ver[i]]) continue;
        tree_DP(ver[i]);
        f[0][u] += max(f[0][ver[i]],f[1][ver[i]]);
        f[1][u] += f[0][ver[i]];
    }
    return max(f[0][u],f[1][u]);
}
void solve(){
    N = qr();a.clear();
    //vis.reset();
    iid = 0;
    memset(fir,0,max_use_fir<<2);
    memset(vis,0,max_use_fir<<2);
    for(Rint i = 1;i<=N;++i){
        cin >> t;
        a.build(t);
    }
    a.get();
    int ans = 0;
    for(Rint i = 1;i<=a.id;++i){
        if(!vis[i])
            ans += tree_DP(i);
    }
    printf("%d\n",ans);
    //printf("0");
}

int main(){
    T = qr();
    while(T--)
        solve();//ע�ⲻ����
    return 0;
}


#include <iostream>
#include <cstdio>
#include <set>
#include <string>
#include <map>
#include <cstring>
#include <queue>
#include <bitset>

using namespace std;

#define il inline
#define Rint register int
#define pr pair<int,int>
#define read(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
#define maxN 1000005
//#define debug
typedef long long ll;
il int qr(){Rint ret=0,f=1;register char ch = getchar();while(!isdigit(ch)) f=ch=='-'?-1:1,ch=getchar();while(isdigit(ch)) ret=ret*10+ch-'0',ch=getchar();return ret*f;}
int T,N;
string t;
int fir[maxN],nxt[maxN<<3],ver[maxN<<3],tot;
int col[maxN],iid,cnt[maxN];
bitset <maxN<<1> vis;
queue <pr> emp,q;
#define nullptr NULL
void lread(int u,int v){
    nxt[++tot] = fir[u];
    fir[u] = tot;
    ver[tot] = v;
}
struct trie{
    struct node{
        int val,id;
        bool use;
        node *fa;
        node *son[30];
        #ifdef debug
        string str;
        #endif // debug
    }t[maxN];
    int top,id;
    node *root;
    node *add_node(node *x,int val){
        x->son[val] = &(t[++top]);
        t[top].fa = x;
        return &t[top];
    }
    node *getson(node *x,int val){
        if(x->son[val] != NULL){
            return x->son[val];
        }else return add_node(x,val);
    }
    void build(string a){
        node *ptr = root;
        for(register unsigned i = 0;i<a.length();++i){
            ptr = getson(ptr,(int)(a[i]-'a'));
        }
    }
    #ifdef debug
    void run_similar(node *fptr,node *sptr,string fword,string rword){
    #endif // debug
    #ifndef debug
    void run_similar(node *fptr,node *sptr/*,string fword,string rword*/){
    #endif // debug
        if(sptr != root){
            if(!fptr->id) fptr -> id = ++id;
            if(!sptr->id) sptr -> id = ++id;
            fptr->use = 1,sptr->use = 1;
            lread(fptr->id,sptr->id);
            lread(sptr->id,fptr->id);
            #ifdef debug
            cout << fword << ' ' << rword << endl;
            cout << sptr->id << ' ' << fptr->id << endl;
            #endif // debug
        }
        node *tfptr,*tsptr;
        for(Rint i = 0;i<26;++i){
            if(fptr->son[i] == nullptr || sptr->son[i] == nullptr) continue;
            tfptr = fptr->son[i],tsptr = sptr->son[i];
            #ifndef debug
            run_similar(tfptr,tsptr);
            #endif // debug
            #ifdef debug
            run_similar(tfptr,tsptr,fword+(char)(i+'a'),rword+(char)(i+'a'));
            #endif // debug
        }
    }
    void get(){
        #ifdef debug
        string str;
        #endif // debug
        node *fptr,*sptr;
        fptr = sptr = root;
        for(Rint i = 0;i<26;++i){
            fptr = root;
            if(fptr -> son[i] == nullptr) continue;
            #ifdef debug
            str = (char)(i+'a');
            #endif // debug
            fptr = fptr -> son[i];
            #ifdef debug
            run_similar(fptr,sptr,str,"");
            #endif // debug
            #ifndef debug
            run_similar(fptr,sptr/*,str,""*/);
            #endif // debug
        }
        for(Rint i = 1;i<=top;++i){
            if(!t[i].use){
                if(!t[i].id) t[i].id = ++id;
                lread(t[i].id,t[i].id);
            }
        }
    }
    void clear(){
        top = 0;id = 0;
        memset(t,0,sizeof(t));
        root = &t[0];
    }
    trie(){
        t[0].fa = nullptr;
        root = &t[0];
    }
}a;
int f[2][maxN];
int tree_DP(int u){
    f[0][u] = 0;
    f[1][u] = 1;
    vis[u] = 1;
    for(Rint i = fir[u];i;i=nxt[i]){
        if(vis[ver[i]]) continue;
        tree_DP(ver[i]);
        f[0][u] += max(f[0][ver[i]],f[1][ver[i]]);
        f[1][u] += f[0][ver[i]];
    }
    return max(f[0][u],f[1][u]);
}
void solve(){
    N = qr();a.clear();
    vis.reset();iid = 0;
    memset(fir,0,sizeof(fir));
    memset(cnt,0,sizeof(cnt));
    for(Rint i = 1;i<=N;++i){
        cin >> t;
        a.build(t);
    }
    a.get();
    int ans = 0;
    for(Rint i = 1;i<=a.id;++i){
        if(!vis[i])
            ans += tree_DP(i);
    }
    printf("%d\n",ans);
}

int main(){
    //read(word);
    T = qr();
    while(T--)
        solve();//ע�ⲻ����
    return 0;
}


#include <iostream>
#include <cstdio>
#include <set>
#include <string>
#include <map>
#include <cstring>
#include <queue>
#include <bitset>

using namespace std;

#define il inline
#define Rint register int
#define pr pair<int,int>
#define read(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
#define maxN 1000005
//#define debug
typedef long long ll;
il int qr(){Rint ret=0,f=1;register char ch = getchar();while(!isdigit(ch)) f=ch=='-'?-1:1,ch=getchar();while(isdigit(ch)) ret=ret*10+ch-'0',ch=getchar();return ret*f;}
int T,N;
string t;
int fir[maxN],nxt[maxN<<3],ver[maxN<<3],tot;
int col[maxN],iid;
//bitset <maxN<<1> vis;
int vis[maxN<<1];
queue <pr> emp,q;
int max_use_fir;
#define nullptr NULL
void lread(int u,int v){
    max_use_fir = max(max_use_fir,u);
    nxt[++tot] = fir[u];
    fir[u] = tot;
    ver[tot] = v;
}
struct trie{
    struct node{
        int val,id;
        bool use;
        node *fa;
        node *son[30];
        #ifdef debug
        string str;
        #endif // debug
    }t[maxN];
    int top,id;
    node *root;
    node *add_node(node *x,int val){
        x->son[val] = &(t[++top]);
        t[top].fa = x;
        return &t[top];
    }
    node *getson(node *x,int val){
        if(x->son[val] != NULL){
            return x->son[val];
        }else return add_node(x,val);
    }
    void build(string a){
        node *ptr = root;
        for(register unsigned i = 0;i<a.length();++i){
            ptr = getson(ptr,(int)(a[i]-'a'));
        }
    }
    #ifdef debug
    void run_similar(node *fptr,node *sptr,string fword,string rword){
    #endif // debug
    #ifndef debug
    void run_similar(node *fptr,node *sptr/*,string fword,string rword*/){
    #endif // debug
        if(sptr != root){
            if(!fptr->id) fptr -> id = ++id;
            if(!sptr->id) sptr -> id = ++id;
            fptr->use = 1,sptr->use = 1;
            lread(fptr->id,sptr->id);
            lread(sptr->id,fptr->id);
            #ifdef debug
            cout << fword << ' ' << rword << endl;
            cout << sptr->id << ' ' << fptr->id << endl;
            #endif // debug
        }
        node *tfptr,*tsptr;
        for(Rint i = 0;i<26;++i){
            if(fptr->son[i] == nullptr || sptr->son[i] == nullptr) continue;
            tfptr = fptr->son[i],tsptr = sptr->son[i];
            #ifndef debug
            run_similar(tfptr,tsptr);
            #endif // debug
            #ifdef debug
            run_similar(tfptr,tsptr,fword+(char)(i+'a'),rword+(char)(i+'a'));
            #endif // debug
        }
    }
    void get(){
        #ifdef debug
        string str;
        #endif // debug
        node *fptr,*sptr;
        fptr = sptr = root;
        for(Rint i = 0;i<26;++i){
            fptr = root;
            if(fptr -> son[i] == nullptr) continue;
            #ifdef debug
            str = (char)(i+'a');
            #endif // debug
            fptr = fptr -> son[i];
            #ifdef debug
            run_similar(fptr,sptr,str,"");
            #endif // debug
            #ifndef debug
            run_similar(fptr,sptr/*,str,""*/);
            #endif // debug
        }
        for(Rint i = 1;i<=top;++i){
            if(!t[i].use){
                if(!t[i].id) t[i].id = ++id;
                lread(t[i].id,t[i].id);
            }
        }
    }
    void clear(){
        memset(t,0,(top+2)*sizeof(t[0]));
        top = 0;id = 0;
        root = &t[0];
    }
    trie(){
        t[0].fa = nullptr;
        root = &t[0];
    }
}a;
int f[2][maxN];
int tree_DP(int u){
    f[0][u] = 0;
    f[1][u] = 1;
    vis[u] = 1;
    for(Rint i = fir[u];i;i=nxt[i]){
        if(vis[ver[i]]) continue;
        tree_DP(ver[i]);
        f[0][u] += max(f[0][ver[i]],f[1][ver[i]]);
        f[1][u] += f[0][ver[i]];
    }
    return max(f[0][u],f[1][u]);
}
void solve(){
    N = qr();a.clear();
    //vis.reset();
    iid = 0;
    memset(fir,0,(max_use_fir+2)<<2);
    memset(vis,0,(max_use_fir+2)<<2);
    for(Rint i = 1;i<=N;++i){
        cin >> t;
        a.build(t);
    }
    a.get();
    int ans = 0;
    for(Rint i = 1;i<=a.id;++i){
        if(!vis[i])
            ans += tree_DP(i);
    }
    printf("%d\n",ans);
    //printf("0");
}

int main(){
    T = qr();
    while(T--)
        solve();//注意不连续
    return 0;
}


#include <iostream>
#include <cstdio>
#include <set>
#include <string>
#include <map>
#include <cstring>
#include <queue>
#include <bitset>

using namespace std;

#define il inline
#define Rint register int
#define pr pair<int,int>
#define read(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
#define maxN 1000005
//#define debug
typedef long long ll;
il int qr(){Rint ret=0,f=1;register char ch = getchar();while(!isdigit(ch)) f=ch=='-'?-1:1,ch=getchar();while(isdigit(ch)) ret=ret*10+ch-'0',ch=getchar();return ret*f;}
int T,N;
string t;
int fir[maxN],nxt[maxN<<3],ver[maxN<<3],tot;
int col[maxN],iid;
//bitset <maxN<<1> vis;
int vis[maxN<<1];
queue <pr> emp,q;
int max_use_fir;
#define nullptr NULL
void lread(int u,int v){
    max_use_fir = max(max_use_fir,u);
    nxt[++tot] = fir[u];
    fir[u] = tot;
    ver[tot] = v;
}
struct trie{
    struct node{
        int val,id;
        bool use;
        node *fa;
        node *son[30];
        #ifdef debug
        string str;
        #endif // debug
    }t[maxN];
    int top,id;
    node *root;
    node *add_node(node *x,int val){
        x->son[val] = &(t[++top]);
        t[top].fa = x;
        return &t[top];
    }
    node *getson(node *x,int val){
        if(x->son[val] != NULL){
            return x->son[val];
        }else return add_node(x,val);
    }
    void build(string a){
        node *ptr = root;
        for(register unsigned i = 0;i<a.length();++i){
            ptr = getson(ptr,(int)(a[i]-'a'));
        }
    }
    #ifdef debug
    void run_similar(node *fptr,node *sptr,string fword,string rword){
    #endif // debug
    #ifndef debug
    void run_similar(node *fptr,node *sptr/*,string fword,string rword*/){
    #endif // debug
        if(sptr != root){
            if(!fptr->id) fptr -> id = ++id;
            if(!sptr->id) sptr -> id = ++id;
            fptr->use = 1,sptr->use = 1;
            lread(fptr->id,sptr->id);
            lread(sptr->id,fptr->id);
            #ifdef debug
            cout << fword << ' ' << rword << endl;
            cout << sptr->id << ' ' << fptr->id << endl;
            #endif // debug
        }
        node *tfptr,*tsptr;
        for(Rint i = 0;i<26;++i){
            if(fptr->son[i] == nullptr || sptr->son[i] == nullptr) continue;
            tfptr = fptr->son[i],tsptr = sptr->son[i];
            #ifndef debug
            run_similar(tfptr,tsptr);
            #endif // debug
            #ifdef debug
            run_similar(tfptr,tsptr,fword+(char)(i+'a'),rword+(char)(i+'a'));
            #endif // debug
        }
    }
    void get(){
        #ifdef debug
        string str;
        #endif // debug
        node *fptr,*sptr;
        fptr = sptr = root;
        for(Rint i = 0;i<26;++i){
            fptr = root;
            if(fptr -> son[i] == nullptr) continue;
            #ifdef debug
            str = (char)(i+'a');
            #endif // debug
            fptr = fptr -> son[i];
            #ifdef debug
            run_similar(fptr,sptr,str,"");
            #endif // debug
            #ifndef debug
            run_similar(fptr,sptr/*,str,""*/);
            #endif // debug
        }
        for(Rint i = 1;i<=top;++i){
            if(!t[i].use){
                if(!t[i].id) t[i].id = ++id;
                lread(t[i].id,t[i].id);
            }
        }
    }
    void clear(){
        memset(t,0,(top+2)*sizeof(t[0]));
        top = 0;id = 0;
        root = &t[0];
    }
    trie(){
        t[0].fa = nullptr;
        root = &t[0];
    }
}a;
int f[2][maxN];
int tree_DP(int u){
    f[0][u] = 0;
    f[1][u] = 1;
    vis[u] = 1;
    for(Rint i = fir[u];i;i=nxt[i]){
        if(vis[ver[i]]) continue;
        tree_DP(ver[i]);
        f[0][u] += max(f[0][ver[i]],f[1][ver[i]]);
        f[1][u] += f[0][ver[i]];
    }
    return max(f[0][u],f[1][u]);
}
void solve(){
    N = qr();a.clear();
    //vis.reset();
    iid = 0;
    memset(fir,0,(max_use_fir+2)<<2);
    memset(vis,0,(max_use_fir+2)<<2);
    for(Rint i = 1;i<=N;++i){
        cin >> t;
        a.build(t);
    }
    a.get();
    int ans = 0;
    for(Rint i = 1;i<=a.id;++i){
        if(!vis[i])
            ans += tree_DP(i);
    }
    printf("%d\n",ans);
    //printf("0");
}

int main(){
    T = qr();
    while(T--)
        solve();//ע�ⲻ����
    return 0;
}


#include <iostream>
#include <cstdio>
#include <set>
#include <string>
#include <map>
#include <cstring>
#include <queue>
#include <bitset>

using namespace std;

#define il inline
#define Rint register int
#define pr pair<int,int>
#define read(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
#define maxN 1000005
//#define debug
typedef long long ll;
il int qr(){Rint ret=0,f=1;register char ch = getchar();while(!isdigit(ch)) f=ch=='-'?-1:1,ch=getchar();while(isdigit(ch)) ret=ret*10+ch-'0',ch=getchar();return ret*f;}
int T,N;
string t;
int fir[maxN],nxt[maxN<<3],ver[maxN<<3],tot;
int col[maxN],iid;
bitset <maxN<<1> vis;
queue <pr> emp,q;
int max_use_fir;
#define nullptr NULL
void lread(int u,int v){
    max_use_fir = max(max_use_fir,u);
    nxt[++tot] = fir[u];
    fir[u] = tot;
    ver[tot] = v;
}
struct trie{
    struct node{
        int val,id;
        bool use;
        node *fa;
        node *son[30];
        #ifdef debug
        string str;
        #endif // debug
    }t[maxN];
    int top,id;
    node *root;
    node *add_node(node *x,int val){
        x->son[val] = &(t[++top]);
        t[top].fa = x;
        return &t[top];
    }
    node *getson(node *x,int val){
        if(x->son[val] != NULL){
            return x->son[val];
        }else return add_node(x,val);
    }
    void build(string a){
        node *ptr = root;
        for(register unsigned i = 0;i<a.length();++i){
            ptr = getson(ptr,(int)(a[i]-'a'));
        }
    }
    #ifdef debug
    void run_similar(node *fptr,node *sptr,string fword,string rword){
    #endif // debug
    #ifndef debug
    void run_similar(node *fptr,node *sptr/*,string fword,string rword*/){
    #endif // debug
        if(sptr != root){
            if(!fptr->id) fptr -> id = ++id;
            if(!sptr->id) sptr -> id = ++id;
            fptr->use = 1,sptr->use = 1;
            lread(fptr->id,sptr->id);
            lread(sptr->id,fptr->id);
            #ifdef debug
            cout << fword << ' ' << rword << endl;
            cout << sptr->id << ' ' << fptr->id << endl;
            #endif // debug
        }
        node *tfptr,*tsptr;
        for(Rint i = 0;i<26;++i){
            if(fptr->son[i] == nullptr || sptr->son[i] == nullptr) continue;
            tfptr = fptr->son[i],tsptr = sptr->son[i];
            #ifndef debug
            run_similar(tfptr,tsptr);
            #endif // debug
            #ifdef debug
            run_similar(tfptr,tsptr,fword+(char)(i+'a'),rword+(char)(i+'a'));
            #endif // debug
        }
    }
    void get(){
        #ifdef debug
        string str;
        #endif // debug
        node *fptr,*sptr;
        fptr = sptr = root;
        for(Rint i = 0;i<26;++i){
            fptr = root;
            if(fptr -> son[i] == nullptr) continue;
            #ifdef debug
            str = (char)(i+'a');
            #endif // debug
            fptr = fptr -> son[i];
            #ifdef debug
            run_similar(fptr,sptr,str,"");
            #endif // debug
            #ifndef debug
            run_similar(fptr,sptr/*,str,""*/);
            #endif // debug
        }
        for(Rint i = 1;i<=top;++i){
            if(!t[i].use){
                if(!t[i].id) t[i].id = ++id;
                lread(t[i].id,t[i].id);
            }
        }
    }
    void clear(){
        top = 0;id = 0;
        memset(t,0,sizeof(t));
        root = &t[0];
    }
    trie(){
        t[0].fa = nullptr;
        root = &t[0];
    }
}a;
int f[2][maxN];
int tree_DP(int u){
    f[0][u] = 0;
    f[1][u] = 1;
    vis[u] = 1;
    for(Rint i = fir[u];i;i=nxt[i]){
        if(vis[ver[i]]) continue;
        tree_DP(ver[i]);
        f[0][u] += max(f[0][ver[i]],f[1][ver[i]]);
        f[1][u] += f[0][ver[i]];
    }
    return max(f[0][u],f[1][u]);
}
void solve(){
    N = qr();a.clear();
    vis.reset();iid = 0;
    memset(fir,0,max_use_fir<<2);
    for(Rint i = 1;i<=N;++i){
        cin >> t;
        a.build(t);
    }
    a.get();
    int ans = 0;
    for(Rint i = 1;i<=a.id;++i){
        if(!vis[i])
            ans += tree_DP(i);
    }
    printf("%d\n",ans);
}

int main(){
    //read(word);
    T = qr();
    while(T--)
        solve();//ע�ⲻ����
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e6 + 1, maxc = 26;
int t, n, m, dep[maxn], e[maxn][maxc | 1], ord[maxn], f[maxn], dp[maxn][2];
char buf[maxn];
int main() {
	scanf("%d", &t);
	while(t--) {
		scanf("%d", &m);
		n = 0;
		memset(e[0], 0, sizeof e[0]);
		while(m--) {
			scanf("%s", buf);
			for(int i = 0, rt = 0; buf[i]; ++i) {
				int o = buf[i] - 'a';
				if(!e[rt][o]) {
					e[rt][o] = ++n;
					memset(e[n], 0, sizeof e[0]);
					dep[n] = dep[rt] + 1;
				}
				rt = e[rt][o];
			}
		}
		n = 0;
		for(int i = 0; i < maxc; ++i)
			if(e[0][i]) {
				f[e[0][i]] = 0;
				ord[++n] = e[0][i];
			}
		for(int i = 1; i <= n; ++i) {
			int u = ord[i];
			for(int j = 0; j < maxc; ++j)
				if(e[u][j]) {
					int v = e[u][j], w = f[u];
					for( ; w && !e[w][j]; w = f[w]);
					f[v] = e[w][j];
					ord[++n] = v;
				}
		}
		memset(dp, 0, (n + 1) * sizeof(dp[0]));
		for(int i = n; i >= 1; --i) {
			int u = ord[i], p = f[u], w = max(dp[u][0], ++dp[u][1]);
			dp[p][0] += w;
			dp[p][1] += dep[p] + 1 < dep[u] ? w : dp[u][0];
		}
		printf("%d\n", dp[0][0]);
	}
	return 0;
}


#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
# include <sys/time.h>
# include <sys/resource.h>
#endif

/*** TEMPLATE CODE STARTS HERE ***/

#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795028841971693993751
#endif

using namespace std;

typedef vector<string> vs;
typedef long long ll;
typedef complex<double> pnt;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;

#define RA(x) begin(x), end(x)
#define FE(i, x) for (auto i = begin(x); i != end(x); ++i)
#define SZ(x) ((ll) (x).size())

template<class T>
void splitstr(const string &s, vector<T> &out)
{
    istringstream in(s);
    out.clear();
    copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

static void redirect(int argc, const char **argv)
{
#ifndef ONLINE_JUDGE
    struct rlimit rlim;
    getrlimit(RLIMIT_STACK, &rlim);
    rlim.rlim_cur = 256 * 1024 * 1024;
    setrlimit(RLIMIT_STACK, &rlim);
    getrlimit(RLIMIT_DATA, &rlim);
    rlim.rlim_cur = 256 * 1024 * 1024;
    setrlimit(RLIMIT_DATA, &rlim);
#endif

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    if (argc > 1)
    {
        static filebuf f;
        f.open(argv[1], ios::in);
        cin.rdbuf(&f);
        if (!cin)
        {
            cerr << "Failed to open '" << argv[1] << "'" << endl;
            exit(1);
        }
    }

    if (argc > 2)
    {
        static filebuf f;
        f.open(argv[2], ios::out | ios::trunc);
        cout.rdbuf(&f);
        if (!cout)
        {
            cerr << "Failed to open '" << argv[2] << "'" << endl;
        }
    }
}

/*** TEMPLATE CODE ENDS HERE */

struct node
{
    char c = 0;
    unique_ptr<node> sib;
    unique_ptr<node> child;
    node *chain = nullptr;
    bool chained = false;

    node *get_child(char ch, bool make = false)
    {
        unique_ptr<node> *cur = &child;
        while ((*cur) && (*cur)->c != ch)
            cur = &(*cur)->sib;
        if ((*cur) && (*cur)->c == ch)
            return (*cur).get();
        else if (make)
        {
            unique_ptr<node> n(new node);
            n->c = ch;
            *cur = move(n);
            return (*cur).get();
        }
        else
            return nullptr;
    }

    int count()
    {
        int ans = 0;
        if (!chained)
        {
            int clen = 0;
            node *p = this;
            while (p)
            {
                clen++;
                p = p->chain;
            }
            ans += clen / 2;
        }
        if (child)
            ans += child->count();
        if (sib)
            ans += sib->count();
        return ans;
    }
};

int main(int argc, const char **argv)
{
    redirect(argc, argv);
    int T;
    cin >> T;
    for (int cas = 0; cas < T; cas++)
    {
        int N;
        cin >> N;
        vector<string> S(N);
        unique_ptr<node> root(new node);
        for (int i = 0; i < N; i++)
        {
            cin >> S[i];
            node *p = root.get();
            node *q = root->get_child(S[i][0], true);
            q->chain = p;
            p->chained = true;
            for (int j = 1; j < SZ(S[i]); j++)
            {
                p = p ? p->get_child(S[i][j], false) : nullptr;
                q = q->get_child(S[i][j], true);
                if (p)
                {
                    q->chain = p;
                    p->chained = true;
                }
            }
        }
        cout << root->count() << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
# include <sys/time.h>
# include <sys/resource.h>
#endif

/*** TEMPLATE CODE STARTS HERE ***/

#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795028841971693993751
#endif

using namespace std;

typedef vector<string> vs;
typedef long long ll;
typedef complex<double> pnt;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;

#define RA(x) begin(x), end(x)
#define FE(i, x) for (auto i = begin(x); i != end(x); ++i)
#define SZ(x) ((ll) (x).size())

template<class T>
void splitstr(const string &s, vector<T> &out)
{
    istringstream in(s);
    out.clear();
    copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

static void redirect(int argc, const char **argv)
{
#ifndef ONLINE_JUDGE
    struct rlimit rlim;
    getrlimit(RLIMIT_STACK, &rlim);
    rlim.rlim_cur = 256 * 1024 * 1024;
    setrlimit(RLIMIT_STACK, &rlim);
    getrlimit(RLIMIT_DATA, &rlim);
    rlim.rlim_cur = 256 * 1024 * 1024;
    setrlimit(RLIMIT_DATA, &rlim);
#endif

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    if (argc > 1)
    {
        static filebuf f;
        f.open(argv[1], ios::in);
        cin.rdbuf(&f);
        if (!cin)
        {
            cerr << "Failed to open '" << argv[1] << "'" << endl;
            exit(1);
        }
    }

    if (argc > 2)
    {
        static filebuf f;
        f.open(argv[2], ios::out | ios::trunc);
        cout.rdbuf(&f);
        if (!cout)
        {
            cerr << "Failed to open '" << argv[2] << "'" << endl;
        }
    }
}

/*** TEMPLATE CODE ENDS HERE */

struct node
{
    char c = 0;
    unique_ptr<node> sib;
    unique_ptr<node> child;
    node *chain = nullptr;
    vector<node *> rchain;

    node *get_child(char ch, bool make = false)
    {
        unique_ptr<node> *cur = &child;
        while ((*cur) && (*cur)->c != ch)
            cur = &(*cur)->sib;
        if ((*cur) && (*cur)->c == ch)
            return (*cur).get();
        else if (make)
        {
            unique_ptr<node> n(new node);
            n->c = ch;
            *cur = move(n);
            return (*cur).get();
        }
        else
            return nullptr;
    }

    array<int, 2> count1()
    {
        array<int, 2> ans{0, 1};
        if (!c)
            ans[1] = 0;
        for (node *s : rchain)
        {
            auto sub = s->count1();
            ans[0] += max(sub[0], sub[1]);
            ans[1] += sub[0];
        }
        return ans;
    }

    int count()
    {
        int ans = 0;
        if (!chain)
        {
            auto sub = count1();
            ans = max(sub[0], sub[1]);
        }
        if (child)
            ans += child->count();
        if (sib)
            ans += sib->count();
        return ans;
    }
};

int main(int argc, const char **argv)
{
    redirect(argc, argv);
    int T;
    cin >> T;
    for (int cas = 0; cas < T; cas++)
    {
        int N;
        cin >> N;
        vector<string> S(N);
        unique_ptr<node> root(new node);
        for (int i = 0; i < N; i++)
        {
            cin >> S[i];
            node *p = root.get();
            for (char c : S[i])
                p = p->get_child(c, true);
        }
        for (int i = 0; i < N; i++)
        {
            node *p = root.get();
            node *q = root->get_child(S[i][0], false);
            if (!q->chain)
            {
                q->chain = p;
                p->rchain.push_back(q);
            }
            for (int j = 1; j < SZ(S[i]); j++)
            {
                p = p->get_child(S[i][j], false);
                if (!p)
                    break;
                q = q->get_child(S[i][j], false);
                if (!q->chain)
                {
                    q->chain = p;
                    p->rchain.push_back(q);
                }
            }
        }
        int ans = root->count();
        cout << ans << '\n';
    }
    return 0;
}


#include<map>
#include<list>
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define il inline
#define ll long long
#define rl register ll
#define ri register int
#define rc register char
using namespace std;
il int read(){
	rc c=' ';
	ri v=0,x=1;
	while((c<'0')||(c>'9')){if(c=='-') x=-1;c=getchar();}
	while((c>='0')&&(c<='9')){v=(v<<1)+(v<<3)+(c^48);c=getchar();}
	return v*x;
}
il void write(rl x){
	if(x<0) x=-x,putchar('-');
	if(x>9) write(x/10);
	putchar(x%10^48);
}
const int N=1e6+10,M=2e6+10;
struct Auto{
	bool vis[N];
	char str[N];
	queue<int> q;
	ll ans,dp[N][2];
	int cnt,head[N],v[M],nxt[M];
	int n,now,tot,ch[N][28],dep[N],fail[N];
	il void clear(){
		for(ri i=0;i<=tot;i++){
			vis[i]=false;
			head[i]=dep[i]=fail[i]=0;
			for(ri j=0;j<26;j++)
				ch[i][j]=0;
		}
		cnt=tot=0;
	}
	il void add(ri x,ri y){
		v[++cnt]=y,nxt[cnt]=head[x],head[x]=cnt;
		v[++cnt]=x,nxt[cnt]=head[y],head[y]=cnt;
	}
	il void insert(){
		scanf("%s",str+1);
		ri now=0,len=strlen(str+1);
		for(ri i=1;i<=len;i++){
			if(!ch[now][str[i]-'a']) dep[++tot]=i,ch[now][str[i]-'a']=tot;
			now=ch[now][str[i]-'a'];
		}
	}
	il void get_fail(){
		for(ri i=0;i<26;i++)
			if(ch[0][i]) q.push(ch[0][i]);
		while(!q.empty()){
			ri u=q.front();
			q.pop();
			for(ri i=0;i<26;i++){
				if(ch[u][i]){
					q.push(ch[u][i]);
					fail[ch[u][i]]=ch[fail[u]][i];
				}
				else ch[u][i]=ch[fail[u]][i];
			}
		}
	}
	il void build(){
		for(ri i=1;i<=tot;i++)
			if(dep[fail[i]]+1==dep[i]&&fail[i]) add(i,fail[i]);
	}
	il void dfs(ri u,ri fa){
		vis[u]=true;
		dp[u][0]=0,dp[u][1]=1;
		for(ri i=head[u];i;i=nxt[i])
			if(v[i]!=fa){
				dfs(v[i],u);
				dp[u][0]+=max(dp[v[i]][0],dp[v[i]][1]);
				dp[u][1]+=dp[v[i]][0];
			}
	}
	il void work(){
		n=read(),ans=0;
		for(ri i=1;i<=n;i++)
			insert();
		get_fail(),build();
		for(ri i=1;i<=tot;i++)
			if(!vis[i]){
				dfs(i,0);
				ans+=max(dp[i][0],dp[i][1]);
			}
		clear();
		write(ans),putchar('\n');
	}
}Trie;
int t;
int main(){
	t=read();
	while(t--) Trie.work();
	return ~~(0-0);
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <ctime>
#define pb push_back
#define ll long long
#define mp make_pair
#define f first
#define s second
#define pii pair < int, int >
#define ull unsigned long long
#define pll pair < ll, ll >
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)
#define all(s) s.begin(), s.end()
#define sz(a) (int)a.size()

const int inf = (1ll << 30) - 1;
const int maxn = (int) 1e5 + 10;

using namespace std;

int nxt[2000100][27];
int link[2000100];
char c[1000100];
int good[2000100];
vector<int> g[2000100];
int sz;
int len;
int ind1[1000100];
int ind2[1000100];
int n;
void clr(int g){
	good[g] = 0;
	link[g] = 0;
	for(int i = 0; i < 26; i++)
		nxt[g][i] = 0;
}

void add(int st, int d){
	int v = 0;
	for(int i = st; i < len; i++){
		int sym = c[i] - 'a';
		if(!nxt[v][sym]){
			clr(sz);
			nxt[v][sym] = sz;
			sz++;
		}
		v = nxt[v][sym];
		good[v] |= d;
	}
}

void go(int ind[], int st){
	int v = 0;
	int g = 0;
	for(int i = st; i < len; i++){
		int sym = c[i] - 'a';
		v = nxt[v][sym];
		ind[g] = v;
		g++;
	}
}

int id[2000100];
int gg;
int par[2000100];

bool used[2000100];

int dfs(int v){
	if(used[v]) return 0;
	used[v] = 1;
	for(int i = 0; i < g[v].size(); i++){
		int to = g[v][i];
		if(par[to] == -1){
			par[to] = v;
			par[v] = to;
			return 1;
		}
		if(dfs(par[v])){
			par[v] = to;
			par[to] = v;
			return 1;
		}
	}
	return 0;
}

void solve(){
	scanf("%d", &n);
	sz = 1;
	clr(0);
	for(int i = 0; i < n; i++){
		scanf("%s", c);
		len = strlen(c);
		add(1, 0);
		go(ind2, 1);
		add(0, 1);
		go(ind1, 0);
		for(int j = 1; j < len; j++)
			link[ind1[j]] = ind2[j-1];
	}
	gg = 0;
	for(int i = 1; i < sz; i++){
		if(good[i]){
			id[i] = gg;
			gg++;
		}
	}
	for(int i=1; i < sz; i++){
		if(good[i]){
			if(good[link[i]]){
				int u = id[i];
				int v = id[link[i]];
				g[u].pb(v);
				g[v].pb(u);
			}
		}
	}
	for(int i = 0; i < gg; i++){
		par[i] = -1;
	}
	for( int run = 1; run; ){
		run = 0;
		for(int i = 0; i < gg; i++)
			used[i] = 0;
		for(int i = 0; i < gg; i++){
			if(par[i] == -1&& dfs(i)){
				run = 1;
			}
		}
	}
	int cnt = 0;
	for(int i = 0; i < gg; i++){
		if(par[i] != -1){
			cnt++;
		}
	}
	printf("%d\n", gg - cnt/2);

	for(int i = 0; i < sz; i++){
		g[i].clear();
	}
}

int main () {
    //cout << "Hello world\n";
    int t=1;
    scanf("%d", &t);
    for(int i=1; i <= t; i++){
      //printf("Case #%d\n", i);
      solve();
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <ctime>
#define pb push_back
#define ll long long
#define mp make_pair
#define f first
#define s second
#define pii pair < int, int >
#define ull unsigned long long
#define pll pair < ll, ll >
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)
#define all(s) s.begin(), s.end()
#define sz(a) (int)a.size()

const int inf = (1ll << 30) - 1;
const int maxn = (int) 1e5 + 10;

using namespace std;

int nxt[2000100][27];
int link[2000100];
char c[1000100];
int good[2000100];
vector<int> g[2000100];
int sz;
int len;
int ind1[1000100];
int ind2[1000100];
int n;
void clr(int g){
	good[g] = 0;
	link[g] = 0;
	for(int i = 0; i < 26; i++)
		nxt[g][i] = 0;
}

void add(int st, int d){
	int v = 0;
	for(int i = st; i < len; i++){
		int sym = c[i] - 'a';
		if(!nxt[v][sym]){
			clr(sz);
			nxt[v][sym] = sz;
			sz++;
		}
		v = nxt[v][sym];
		good[v] |= d;
	}
}

void go(int ind[], int st){
	int v = 0;
	int g = 0;
	for(int i = st; i < len; i++){
		int sym = c[i] - 'a';
		v = nxt[v][sym];
		ind[g] = v;
		g++;
	}
}

int id[2000100];
int gg;
int par[2000100];

bool used[2000100];

int dfs(int v){
	if(used[v]) return 0;
	used[v] = 1;
	for(int i = 0; i < g[v].size(); i++){
		int to = g[v][i];
		if(par[to] == -1){
			par[to] = v;
			par[v] = to;
			return 1;
		}
		if(dfs(par[to])){
			par[v] = to;
			par[to] = v;
			return 1;
		}
	}
	return 0;
}

void solve(){
	scanf("%d", &n);
	sz = 1;
	clr(0);
	for(int i = 0; i < n; i++){
		scanf("%s", c);
		len = strlen(c);
		add(1, 0);
		go(ind2, 1);
		add(0, 1);
		go(ind1, 0);
		for(int j = 1; j < len; j++)
			link[ind1[j]] = ind2[j-1];
	}
	gg = 0;
	for(int i = 1; i < sz; i++){
		if(good[i]){
			id[i] = gg;
			gg++;
		}
	}
	for(int i=1; i < sz; i++){
		if(good[i]){
			if(good[link[i]]){
				int u = id[i];
				int v = id[link[i]];
				g[u].pb(v);
				g[v].pb(u);
			}
		}
	}
	for(int i = 0; i < gg; i++){
		par[i] = -1;
	}
	for( int run = 1; run; ){
		run = 0;
		for(int i = 0; i < gg; i++)
			used[i] = 0;
		for(int i = 0; i < gg; i++){
			if(par[i] == -1&& dfs(i)){
				run = 1;
			}
		}
	}
	int cnt = 0;
	for(int i = 0; i < gg; i++){
		if(par[i] != -1){
			cnt++;
		}
	}
	printf("%d\n", gg - cnt/2);

	for(int i = 0; i < sz; i++){
		g[i].clear();
	}
}

int main () {
    //cout << "Hello world\n";
    int t=1;
    scanf("%d", &t);
    for(int i=1; i <= t; i++){
      //printf("Case #%d\n", i);
      solve();
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <ctime>
#define pb push_back
#define ll long long
#define mp make_pair
#define f first
#define s second
#define pii pair < int, int >
#define ull unsigned long long
#define pll pair < ll, ll >
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)
#define all(s) s.begin(), s.end()
#define sz(a) (int)a.size()

const int inf = (1ll << 30) - 1;
const int maxn = (int) 1e5 + 10;

using namespace std;

int nxt[2000100][27];
int link[2000100];
char c[1000100];
int good[1000100];
vector<int> g[2000100];
int sz;
int len;
int ind1[1000100];
int ind2[1000100];
int n;
void clr(int g){
	good[g] = 0;
	link[g] = 0;
	for(int i = 0; i < 26; i++)
		nxt[g][i] = 0;
}

void add(int st, int d){
	int v = 0;
	for(int i = st; i < len; i++){
		int sym = c[i] - 'a';
		if(!nxt[v][sym]){
			clr(sz);
			nxt[v][sym] = sz;
			sz++;
		}
		v = nxt[v][sym];
		good[v] |= d;
	}
}

void go(int ind[], int st){
	int v = 0;
	int g = 0;
	for(int i = st; i < len; i++){
		int sym = c[i] - 'a';
		v = nxt[v][sym];
		ind[g] = v;
		g++;
	}
}

int id[2000100];
int gg;
int par[2000100];

bool used[2000100];

int dfs(int v){
	if(used[v]) return 0;
	used[v] = 1;
	for(int i = 0; i < g[v].size(); i++){
		int to = g[v][i];
		if(par[to] == -1){
			par[to] = v;
			par[v] = to;
			return 1;
		}
		if(dfs(par[v])){
			par[v] = to;
			par[to] = v;
			return 1;
		}
	}
	return 0;
}

void solve(){
	scanf("%d", &n);
	sz = 1;
	clr(0);
	for(int i = 0; i < n; i++){
		scanf("%s", c);
		len = strlen(c);
		add(1, 0);
		go(ind2, 1);
		add(0, 1);
		go(ind1, 0);
		for(int j = 1; j < len; j++)
			link[ind1[j]] = ind2[j-1];
	}
	gg = 0;
	for(int i = 1; i < sz; i++){
		if(good[i]){
			id[i] = gg;
			gg++;
		}
	}
	for(int i=1; i < sz; i++){
		if(good[i]){
			if(good[link[i]]){
				int u = id[i];
				int v = id[link[i]];
				g[u].pb(v);
				g[v].pb(u);
			}
		}
	}
	for(int i = 0; i < gg; i++){
		par[i] = -1;
	}
	for( int run = 1; run; ){
		run = 0;
		for(int i = 0; i < gg; i++)
			used[i] = 0;
		for(int i = 0; i < gg; i++){
			if(par[i] == -1&& dfs(i)){
				run = 1;
			}
		}
	}
	int cnt = 0;
	for(int i = 0; i < gg; i++){
		if(par[i] != -1){
			cnt++;
		}
	}
	printf("%d\n", gg - cnt/2);

	for(int i = 0; i < sz; i++){
		g[i].clear();
	}
}

int main () {
    //cout << "Hello world\n";
    int t=1;
    scanf("%d", &t);
    for(int i=1; i <= t; i++){
      //printf("Case #%d\n", i);
      solve();
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
const int maxm = 26;
int tot, n;
int ch[maxn][maxm];
int newNode()
{
    memset(ch[tot], 0, sizeof ch[tot]);
    return tot++;
}
char s[maxn];
void add(char *s)
{
    int len = strlen(s);
    int cur = 0;
    for(int i = 0; i < len; ++ i)
    {
        int v = s[i] - 'a';
        if(ch[cur][v] == 0) ch[cur][v] = newNode();
        cur = ch[cur][v];
    }
}
string str[maxn];
vector<int> G[maxn];
void build(const string &s)
{
    int a = 0;
    int b = ch[0][s[0]-'a'];
    for(int i = 1; i < s.size(); ++ i)
    {
        int v = s[i] - 'a';
        a = ch[a][v];
        b = ch[b][v];
        if(a == 0 || b == 0) return;
        G[a].push_back(b);
        G[b].push_back(a);
    }
}
int f[maxn][2];
bool vis[maxn];
void dfs(int u)
{
    vis[u] = true;
    f[u][0] = 0;
    f[u][1] = 1;
    for(auto v : G[u])
    {
        if(vis[v]) continue;
        dfs(v);
        f[u][0] += max(f[v][0], f[v][1]);
        f[u][1] += f[v][0];
    }
}
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        tot=1;
        cin>>n;
        memset(ch[0],0,sizeof ch[0]);
        for(int i=0;i<n;i++)
        {
            scanf("%s",s);
            add(s);
            str[i]=s;
        }
        for(int i=1;i<tot;i++)
            G[i].clear();
        for(int i=0; i<n;i++)
            build(str[i]);
        for(int i=1;i<=tot;i++)
            vis[i] = false;
        int res=0;
        for(int i=1;i<tot;i++)
        {
            if(!vis[i])
            {
                dfs(i);
                res+=max(f[i][0],f[i][1]);
            }
        }
        cout<<res<<endl;
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
const int maxn=1000010;
int n;
char s[maxn];
vector<int>g[maxn];
void add(int x,int y){
	//printf("%d - %d\n",x,y);
	g[x].push_back(y);g[y].push_back(x);
}
int root;
struct Trie{
	int ch[maxn][26],e;
	void init(){
		e=1;
	}
	void insert(char* s,int len){
		int o=1;
		for(int i=0;i<len;i++){
			int c=s[i]-'a';
			if(!ch[o][c]) ch[o][c]=++e;
			o=ch[o][c];
		}
	}
	void dfs(int cor,int x){
		//printf("cor=%d x=%d\n",cor,x);
		for(int i=0;i<26;i++){
			if(ch[cor][i] && ch[x][i]){
				add(ch[cor][i],ch[x][i]);
				dfs(ch[cor][i],ch[x][i]);
			}
		}
	}
}T;
int fa[maxn],dp[maxn][2],vis[maxn];
void dfs(int x,int f){
	dp[x][1]=1;dp[x][0]=0;vis[x]=1;
	for(int i=0;i<g[x].size();i++){
		int v=g[x][i];
		if(v==f) continue;
		dfs(v,x);
		dp[x][0]+=max(dp[v][0],dp[v][1]);
		dp[x][1]+=dp[v][0];
	}
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		T.init();
		for(int i=1;i<=n;i++){
			scanf("%s",s+1);
			T.insert(s+1,strlen(s+1));
		}
		for(int i=0;i<26;i++){
			if(T.ch[1][i]) T.dfs(1,T.ch[1][i]);
		}
		//printf("size=%d\n",(int)g[5].size());
		//printf("root=%d\n",root);
		int ans=0;
		for(int i=2;i<=T.e;i++){
			if(!vis[i]){
				dfs(i,0),ans+=max(dp[i][0],dp[i][1]);
			}
		}
		printf("%d\n",ans);
		for(int i=1;i<=T.e;i++) g[i].clear();
		for(int i=1;i<=T.e;i++) vis[i]=0,dp[i][0]=dp[i][1]=0;
		for(int i=1;i<=T.e;i++) T.ch[i][0]=T.ch[i][1]=0;
	}
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<string>
#include<iostream>
using namespace std;
const int maxn=2000010;
int n;
vector<int>g[maxn];
void add(int x,int y){
	g[x].push_back(y);g[y].push_back(x);
}
int root;
struct Trie{
	int ch[maxn][26],e,cnt;
	void init(){
		e=1;
		memset(ch[1],0,sizeof(ch[1]));
	}
	void insert(string s,int len){
		int o=1;
		for(int i=0;i<len;i++){
			int c=s[i]-'a';
			if(!ch[o][c]) ch[o][c]=++e,memset(ch[e],0,sizeof(ch[e]));
			o=ch[o][c];
		}
	}
	void dfs(int cor,int x){
		//printf("cor=%d x=%d\n",cor,x);
		for(int i=0;i<26;i++){
			if(ch[cor][i] && ch[x][i]){
				add(ch[cor][i],ch[x][i]);
				dfs(ch[cor][i],ch[x][i]);
			}
		}
	}
}T;
int fa[maxn],dp[maxn][2],vis[maxn];
void dfs(int x,int f){
	dp[x][1]=1;dp[x][0]=0;vis[x]=1;
	for(int i=0;i<g[x].size();i++){
		int v=g[x][i];
		if(v==f) continue;
		dfs(v,x);
		dp[x][0]+=max(dp[v][0],dp[v][1]);
		dp[x][1]+=dp[v][0];
	}
}
string s[maxn];
int main(){
	int t;
	scanf("%d",&t);
	int cnt=0;
	while(t--){
		scanf("%d",&n);
		T.init();T.e=1;
		for(int i=1;i<=n;i++){
			cin>>s[i];
			T.insert(s[i],s[i].length());
		}
		for(int i=1;i<=T.e;i++) vis[i]=0,dp[i][0]=dp[i][1]=0;
		for(int i=1;i<=T.e;i++) g[i].clear();
		for(int i=0;i<26;i++){
			if(T.ch[1][i]) T.dfs(1,T.ch[1][i]);
		}
		int ans=0;
		for(int i=2;i<=T.e;i++){
			if(!vis[i]){
				dfs(i,0),ans+=max(dp[i][0],dp[i][1]);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<string>
#include<iostream>
using namespace std;
const int maxn=2000010;
int n;
vector<int>g[maxn];
void add(int x,int y){
	//printf("%d - %d\n",x,y);
	g[x].push_back(y);g[y].push_back(x);
}
int root;
struct Trie{
	int ch[maxn][26],e;
	void init(){
		e=1;
	}
	void insert(string s,int len){
		int o=1;
		for(int i=0;i<len;i++){
			int c=s[i]-'a';
			if(!ch[o][c]) ch[o][c]=++e;
			o=ch[o][c];
		}
	}
	void dfs(int cor,int x){
		//printf("cor=%d x=%d\n",cor,x);
		for(int i=0;i<26;i++){
			if(ch[cor][i] && ch[x][i]){
				add(ch[cor][i],ch[x][i]);
				dfs(ch[cor][i],ch[x][i]);
			}
		}
	}
	void get(string s,int pos){
		int o=ch[1][s[0]-'a'];
		//printf("%d %d\n",pos,o);
		for(int i=1;i<s.length();i++){
			int c=s[i]-'a';
			if(ch[pos][c] && ch[o][c]){
				add(ch[pos][c],ch[o][c]);
				pos=ch[pos][c],o=ch[o][c];
			}
		}
	}
}T;
int fa[maxn],dp[maxn][2],vis[maxn];
void dfs(int x,int f){
	dp[x][1]=1;dp[x][0]=0;vis[x]=1;
	for(int i=0;i<g[x].size();i++){
		int v=g[x][i];
		if(v==f) continue;
		dfs(v,x);
		dp[x][0]+=max(dp[v][0],dp[v][1]);
		dp[x][1]+=dp[v][0];
	}
}
string s[maxn];
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		T.init();
		for(int i=1;i<=n;i++){
			cin>>s[i];
			T.insert(s[i],s[i].length());
		}
		/*for(int i=0;i<26;i++){
			if(T.ch[1][i]) T.dfs(1,T.ch[1][i]);
		}*/
		for(int i=1;i<=n;i++){
			//cout<<s[i]<<endl;
			T.get(s[i],1);
		}
		//printf("size=%d\n",(int)g[5].size());
		//printf("root=%d\n",root);
		int ans=0;
		for(int i=2;i<=T.e;i++){
			if(!vis[i]){
				dfs(i,0),ans+=max(dp[i][0],dp[i][1]);
			}
		}
		printf("%d\n",ans);
		for(int i=1;i<=T.e;i++) g[i].clear();
		for(int i=1;i<=T.e;i++) vis[i]=0,dp[i][0]=dp[i][1]=0;
		for(int i=1;i<=T.e;i++) T.ch[i][0]=T.ch[i][1]=0;
	}
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<string>
#include<iostream>
using namespace std;
const int maxn=1000010;
int n;
vector<int>g[maxn];
void add(int x,int y){
	//printf("%d - %d\n",x,y);
	g[x].push_back(y);g[y].push_back(x);
}
int root;
struct Trie{
	int ch[maxn][26],e;
	void init(){
		e=1;
	}
	void insert(string s,int len){
		int o=1;
		for(int i=0;i<len;i++){
			int c=s[i]-'a';
			if(!ch[o][c]) ch[o][c]=++e;
			o=ch[o][c];
		}
	}
	void dfs(int cor,int x){
		//printf("cor=%d x=%d\n",cor,x);
		for(int i=0;i<26;i++){
			if(ch[cor][i] && ch[x][i]){
				add(ch[cor][i],ch[x][i]);
				dfs(ch[cor][i],ch[x][i]);
			}
		}
	}
	void get(string s,int pos){
		int o=ch[1][s[0]-'a'];
		//printf("%d %d\n",pos,o);
		for(int i=1;i<s.length();i++){
			int c=s[i]-'a';
			if(ch[pos][c] && ch[o][c]){
				add(ch[pos][c],ch[o][c]);
				pos=ch[pos][c],o=ch[o][c];
			}
		}
	}
}T;
int fa[maxn],dp[maxn][2],vis[maxn];
void dfs(int x,int f){
	dp[x][1]=1;dp[x][0]=0;vis[x]=1;
	for(int i=0;i<g[x].size();i++){
		int v=g[x][i];
		if(v==f) continue;
		dfs(v,x);
		dp[x][0]+=max(dp[v][0],dp[v][1]);
		dp[x][1]+=dp[v][0];
	}
}
string s[maxn];
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		T.init();
		for(int i=1;i<=n;i++){
			cin>>s[i];
			T.insert(s[i],s[i].length());
		}
		/*for(int i=0;i<26;i++){
			if(T.ch[1][i]) T.dfs(1,T.ch[1][i]);
		}*/
		for(int i=1;i<=n;i++){
			//cout<<s[i]<<endl;
			T.get(s[i],1);
		}
		//printf("size=%d\n",(int)g[5].size());
		//printf("root=%d\n",root);
		int ans=0;
		for(int i=2;i<=T.e;i++){
			if(!vis[i]){
				dfs(i,0),ans+=max(dp[i][0],dp[i][1]);
			}
		}
		printf("%d\n",ans);
		for(int i=1;i<=T.e;i++) g[i].clear();
		for(int i=1;i<=T.e;i++) vis[i]=0,dp[i][0]=dp[i][1]=0;
		for(int i=1;i<=T.e;i++) T.ch[i][0]=T.ch[i][1]=0;
	}
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
const int maxn=1000010;
int n;
char s[maxn];
vector<int>g[maxn];
void add(int x,int y){
	//printf("%d - %d\n",x,y);
	g[x].push_back(y);g[y].push_back(x);
}
int root;
struct Trie{
	int ch[maxn][26],e;
	void init(){
		e=1;root=0;
		memset(ch,0,sizeof(ch));
	}
	void insert(char* s,int len){
		int o=1;
		for(int i=0;i<len;i++){
			int c=s[i]-'a';
			if(!ch[o][c]) ch[o][c]=++e;
			o=ch[o][c];
		}
	}
	void dfs(int cor,int x){
		//printf("cor=%d x=%d\n",cor,x);
		for(int i=0;i<26;i++){
			if(ch[cor][i] && ch[x][i]){
				add(ch[cor][i],ch[x][i]);
				dfs(ch[cor][i],ch[x][i]);
			}
		}
	}
}T;
int fa[maxn],dp[maxn][2],vis[maxn];
void dfs(int x){
	dp[x][1]=1;dp[x][0]=0;vis[x]=1;
	for(int i=0;i<g[x].size();i++){
		int v=g[x][i];
		if(v==fa[x]) continue;
		fa[v]=x;
		dfs(v);
		dp[x][0]+=max(dp[v][0],dp[v][1]);
		dp[x][1]+=dp[v][0];
	}
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		memset(fa,0,sizeof(fa));
		T.init();
		for(int i=1;i<=n;i++){
			scanf("%s",s+1);
			T.insert(s+1,strlen(s+1));
		}
		for(int i=1;i<=T.e;i++) g[i].clear();
		for(int i=0;i<26;i++){
			if(T.ch[1][i]) T.dfs(1,T.ch[1][i]);
		}
		//printf("size=%d\n",(int)g[5].size());
		//printf("root=%d\n",root);
		memset(dp,0,sizeof(dp));memset(vis,0,sizeof(vis));
		int ans=0;
		for(int i=2;i<=T.e;i++){
			if(!vis[i]){
				dfs(i),ans+=max(dp[i][0],dp[i][1]);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include<bits/stdc++.h>
#define MAXN 1000005
#define INF 1000000000
#define MOD1 1000000007
#define MOD2 1000000009
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n,t;
map<P,ll> mp;
vector<ll> G[MAXN];
string str[MAXN];
ll color[MAXN],cnt1,cnt2;
bool valid[MAXN];
bool solve(ll v,ll c)
{
	if(c==1) cnt1++; else cnt2++;
	color[v]=c;
	for(ll i=0;i<G[v].size();i++)
		if(color[G[v][i]]==0) solve(G[v][i],-c);
}
void add_edge(ll x,ll y)
{
	G[x].push_back(y);
	G[y].push_back(x);
}
int main()
{
	scanf("%I64d",&t);
	while(t--)
	{
		scanf("%I64d",&n);
		ll cnt=2,tt=1;
		for(ll i=1;i<=n;i++)
			G[i].clear();
		memset(valid,true,sizeof(valid));
		mp.clear();
		for(ll i=0;i<n;i++)
		{
			cin>>str[i];
			ll len=str[i].size();
			ll s1=0,s2=0;
			for(ll j=0;j<len;j++)
			{
				s1=(s1*97+str[i][j]+1-'a')%MOD1;
				s2=(s2*97+str[i][j]+1-'a')%MOD2;
				if(mp.find(P(s1,s2))!=mp.end())
				{
					valid[tt]=false;
					tt++; continue;
				}
				mp[P(s1,s2)]=tt;
				tt++;
			}
		}
		for(ll i=0;i<n;i++)
		{
			ll len=str[i].size();
			ll s1=0,s2=0;
			for(ll j=1;j<len;j++)
			{
				s1=(s1*97+str[i][j]+1-'a')%MOD1;
				s2=(s2*97+str[i][j]+1-'a')%MOD2;
				if(!valid[cnt]) {cnt++; continue;}
				if(mp.find(P(s1,s2))!=mp.end()) add_edge(cnt,mp[P(s1,s2)]);
				cnt++;
			}
			cnt++;
		}
		ll ans=0;
		for(ll i=1;i<tt;i++)
			color[i]=0;
		for(ll i=1;i<tt;i++)
		{
			if(!valid[i]) continue;
			if(color[i]==0)
			{
				cnt1=0,cnt2=0;
				solve(i,1);
				ans+=max(cnt1,cnt2);
			}
		}
		printf("%I64d\n",ans);
	}
	return 0;
}


#include<bits/stdc++.h>
#define MAXN 1000005
#define INF 1000000000
#define MOD1 1000000007
#define MOD2 1000000009
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n,t;
set<ll> s;
struct node
{
	ll hash,pre,len;
}a[MAXN];
string str;
bool cmp(node x,node y)
{
	return x.len>y.len;
}
int main()
{
	scanf("%I64d",&t);
	while(t--)
	{
		ll tt=0;
		scanf("%I64d",&n);
		s.clear();
		for(ll i=0;i<n;i++)
		{
			cin>>str;
			ll len=(ll)str.size();
			ll s1=0,s2=0,s3=0,s4=0;
			for(ll j=0;j<len;j++)
			{
				s1=(s1*97+str[j]+1-'a')%MOD1;
				s2=(s2*97+str[j]+1-'a')%MOD2;
				if(j>0)
				{
					s3=(s3*97+str[j]+1-'a')%MOD1;
				 	s4=(s4*97+str[j]+1-'a')%MOD2;
				 	a[tt].pre=s3*MOD1+s4;
				}
				else a[tt].pre=-1;
				a[tt].hash=s1*MOD1+s2;
				s.insert(a[tt].hash);
				a[tt].len=j;
				tt++;
			}
		}
		sort(a,a+tt,cmp);
		for(ll i=0;i<tt;i++)
			if(s.count(a[i].hash)) s.erase(a[i].pre);
		printf("%d\n",s.size());
	}
	return 0;
}


#include<map>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<vector>
#define MAXN 1000005
#define INF 1000000000
#define MOD1 1000000007
#define MOD2 1000000009
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n,t;
map<P,ll> mp;
vector<ll> G[MAXN];
string str[MAXN];
ll color[MAXN],cnt1,cnt2;
bool valid[MAXN];
void solve(ll v,ll c)
{
	if(c==1) cnt1++; else cnt2++;
	color[v]=c;
	for(ll i=0;i<G[v].size();i++)
		if(color[G[v][i]]==0) solve(G[v][i],-c);
}
void add_edge(ll x,ll y)
{
	G[x].push_back(y);
	G[y].push_back(x);
}
int main()
{
	scanf("%I64d",&t);
	while(t--)
	{
		scanf("%I64d",&n);
		ll cnt=2,tt=1;
		for(ll i=1;i<=n;i++)
			G[i].clear();
		memset(valid,true,sizeof(valid));
		mp.clear();
		for(ll i=0;i<n;i++)
		{
			cin>>str[i];
			ll len=str[i].size();
			ll s1=0,s2=0;
			for(ll j=0;j<len;j++)
			{
				s1=(s1*97+str[i][j]+1-'a')%MOD1;
				s2=(s2*97+str[i][j]+1-'a')%MOD2;
				if(mp.find(P(s1,s2))!=mp.end())
				{
					valid[tt]=false;
					tt++; continue;
				}
				mp[P(s1,s2)]=tt;
				tt++;
			}
		}
		for(ll i=0;i<n;i++)
		{
			ll len=str[i].size();
			ll s1=0,s2=0;
			for(ll j=1;j<len;j++)
			{
				s1=(s1*97+str[i][j]+1-'a')%MOD1;
				s2=(s2*97+str[i][j]+1-'a')%MOD2;
				if(!valid[cnt]) {cnt++; continue;}
				if(mp.find(P(s1,s2))!=mp.end()) add_edge(cnt,mp[P(s1,s2)]);
				cnt++;
			}
			cnt++;
		}
		ll ans=0;
		for(ll i=1;i<tt;i++)
			color[i]=0;
		for(ll i=1;i<tt;i++)
		{
			if(!valid[i]) continue;
			if(color[i]==0)
			{
				cnt1=0,cnt2=0;
				solve(i,1);
				ans+=max(cnt1,cnt2);
			}
		}
		printf("%I64d\n",ans);
	}
	return 0;
}


#include<bits/stdc++.h>
#define MAXN 1000005
#define INF 1000000000
#define MOD1 1000000007
#define MOD2 1000000009
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n,t;
struct node
{
	ll hash,pre,len;
}a[MAXN];
string str;
bool cmp(node x,node y)
{
	return x.len>y.len;
}
int main()
{
	scanf("%I64d",&t);
	while(t--)
	{
		ll tt=0;
		scanf("%I64d",&n);
		set<ll> s;
		for(ll i=0;i<n;i++)
		{
			cin>>str;
			ll len=(ll)str.size();
			ll s1=0,s2=0,s3=0,s4=0;
			for(ll j=0;j<len;j++)
			{
				s1=(s1*97+str[j]+1-'a')%MOD1;
				s2=(s2*97+str[j]+1-'a')%MOD2;
				if(j>0)
				{
					s3=(s3*97+str[j]+1-'a')%MOD1;
				 	s4=(s4*97+str[j]+1-'a')%MOD2;
				 	a[tt].pre=s3*MOD1+s4;
				}
				else a[tt].pre=-1;
				a[tt].hash=s1*MOD1+s2;
				s.insert(a[tt].hash);
				a[tt].len=j;
				tt++;
			}
		}
		sort(a,a+tt,cmp);
		for(ll i=0;i<tt;i++)
			if(s.count(a[i].hash)) s.erase(a[i].pre);
		printf("%d\n",s.size());
	}
	return 0;
}


#include<bits/stdc++.h>
#include<unordered_map>
#define MAXN 1000005
#define INF 1000000000
#define MOD1 1000000007
#define MOD2 1000000009
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n,t;
unordered_map<P,ll> mp;
vector<ll> G[MAXN];
string str[MAXN];
ll color[MAXN],cnt1,cnt2;
bool valid[MAXN];
bool solve(ll v,ll c)
{
	if(c==1) cnt1++; else cnt2++;
	color[v]=c;
	for(ll i=0;i<G[v].size();i++)
		if(color[G[v][i]]==0) solve(G[v][i],-c);
}
void add_edge(ll x,ll y)
{
	G[x].push_back(y);
	G[y].push_back(x);
}
int main()
{
	scanf("%I64d",&t);
	while(t--)
	{
		scanf("%I64d",&n);
		ll cnt=2,tt=1;
		for(ll i=1;i<=n;i++)
			G[i].clear();
		memset(valid,true,sizeof(valid));
		mp.clear();
		for(ll i=0;i<n;i++)
		{
			cin>>str[i];
			ll len=str[i].size();
			ll s1=0,s2=0;
			for(ll j=0;j<len;j++)
			{
				s1=(s1*97+str[i][j]+1-'a')%MOD1;
				s2=(s2*97+str[i][j]+1-'a')%MOD2;
				if(mp.find(P(s1,s2))!=mp.end())
				{
					valid[tt]=false;
					tt++; continue;
				}
				mp[P(s1,s2)]=tt;
				tt++;
			}
		}
		for(ll i=0;i<n;i++)
		{
			ll len=str[i].size();
			ll s1=0,s2=0;
			for(ll j=1;j<len;j++)
			{
				s1=(s1*97+str[i][j]+1-'a')%MOD1;
				s2=(s2*97+str[i][j]+1-'a')%MOD2;
				if(!valid[cnt]) {cnt++; continue;}
				if(mp.find(P(s1,s2))!=mp.end()) add_edge(cnt,mp[P(s1,s2)]);
				cnt++;
			}
			cnt++;
		}
		ll ans=0;
		for(ll i=1;i<tt;i++)
			color[i]=0;
		for(ll i=1;i<tt;i++)
		{
			if(!valid[i]) continue;
			if(color[i]==0)
			{
				cnt1=0,cnt2=0;
				solve(i,1);
				ans+=max(cnt1,cnt2);
			}
		}
		printf("%I64d\n",ans);
	}
	return 0;
}


#include<bits/stdc++.h>
#define MAXN 1000005
#define INF 1000000000
#define MOD1 1000000007
#define MOD2 1000000009
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n,t;
struct node
{
	ll hash,pre,len;
}a[MAXN];
char str[MAXN];
bool cmp(node x,node y)
{
	return x.len>y.len;
}
int main()
{
	scanf("%I64d",&t);
	while(t--)
	{
		ll tt=0;
		scanf("%I64d",&n);
		set<ll> s;
		for(ll i=0;i<n;i++)
		{
			scanf("%s",str);
			ll len=strlen(str);
			ll s1=0,s2=0,s3=0,s4=0;
			for(ll j=0;j<len;j++)
			{
				s1=(s1*97+str[j]+1-'a')%MOD1;
				s2=(s2*97+str[j]+1-'a')%MOD2;
				if(j>0)
				{
					s3=(s3*97+str[j]+1-'a')%MOD1;
				 	s4=(s4*97+str[j]+1-'a')%MOD2;
				 	a[tt].pre=s3*MOD1+s4;
				}
				else a[tt].pre=-1;
				a[tt].hash=s1*MOD1+s2;
				s.insert(a[tt].hash);
				a[tt].len=j;
				tt++;
			}
		}
		sort(a,a+tt,cmp);
		for(ll i=0;i<tt;i++)
			if(s.count(a[i].hash)) s.erase(a[i].pre);
		printf("%d\n",s.size());
	}
	return 0;
}


for _ in range(int(input())):
    n=int(input())
    d={}
    for _ in range(n):
        x,y=map(int,input().split())
        if d.get(x)==None:
            d[x]=[y]
        else:
            d[x].append(y)
    k=sorted(list(d.keys()))
    mn=-1
    flag=True
    st=str()
    currx=0
    curry=0
    for i in k:
        for _ in range(i-currx):
            st+="R"
        currx=i
        mx=max(d[i])
        if mn>min(d[i]):
            flag=False
            break
        mn=mx
        for _ in range(mx-curry):
            st+="U"
        curry=mx
    if flag:
        print("YES")
        print(st)
    else:
        print("NO")


for _ in range(int(input())):
    n=int(input())
    d={}
    for _ in range(n):
        x,y=map(int,input().split())
        if d.get(x)==None:
            d[x]=[y]
        else:
            d[x].append(y)
    k=sorted(list(d.keys()))
    mn=-1
    flag=True
    st=str()
    currx=0
    curry=0
    for i in k:
        for t in range(i-currx):
            st+="R"
        currx=i
        mx=max(d[i])
        if mn>mx:
            flag=False
            break
        mn=mx
        for _ in range(mx-curry):
            st+="U"
        curry=mx
    if flag:
        print("YES")
        print(st)
    else:
        print("NO")


for _ in range(int(input())):
    n=int(input())
    d={}
    for _ in range(n):
        x,y=map(int,input().split())
        if d.get(x)==None:
            d[x]=[y]
        else:
            d[x].append(y)
    k=sorted(list(d.keys()))
    mn=-1
    flag=True
    st=str()
    currx=0
    curry=0
    for i in k:
        for t in range(i-currx):
            st+="R"
        currx=i
        mx=max(d[i])
        if mn>mx:
            flag=False
            break
        mn=mx
        for i in range(mx-curry):
            st+="U"
        curry=mx
    if flag:
        print("YES")
        print(st)
    else:
        print("NO")


t = int(input())
for _ in range(t):
    n = int(input())
    a = []
    ans = ''
    count = 0
    robot_cord = [0, 0]
    for i in range(n):
        a.append(list(map(int, input().split())))
    need_y = 0
    while robot_cord[0] < 1001 and count < n:
        for i in range(n):
            if a[i][0] == robot_cord[0]:
                if robot_cord[1] < a[i][1]:
                    count += 1
                if a[i][1] > need_y:
                    need_y = a[i][1]
        if need_y > robot_cord[1]:
            ans += 'U' * (need_y - robot_cord[1])
            robot_cord[1] = need_y
        if count < n:
            robot_cord[0] += 1
            ans += 'R'
            if robot_cord in a:
                count += 1
    if count == n:
        print('YES')
        print(ans)
    else:
        print('NO')


t = int(input())
for _ in range(t):
    n = int(input())
    a = []
    ans = ''
    count = 0
    robot_cord = [0, 0]
    for i in range(n):
        a.append(list(map(int, input().split())))
    need_y = 0
    while robot_cord[0] < 100 and count < n:
        for i in range(n):
            if a[i][0] == robot_cord[0]:
                if robot_cord[1] < a[i][1]:
                    count += 1
                if a[i][1] > need_y:
                    need_y = a[i][1]
        if need_y > robot_cord[1]:
            ans += 'U' * (need_y - robot_cord[1])
            robot_cord[1] = need_y
        if count < n:
            robot_cord[0] += 1
            ans += 'R'
            if robot_cord in a:
                count += 1
    if count == n:
        print('YES')
        print(ans)
    else:
        print('NO')


t = int(input())
for _ in range(t):
    n = int(input())
    a = []
    ans = ''
    count = 0
    robot_cord = [0, 0]
    for i in range(n):
        a.append(list(map(int, input().split())))
    need_y = 0
    while robot_cord[1] < 100 and count < n:
        for i in range(n):
            if a[i][0] == robot_cord[0]:
                if robot_cord[1] < a[i][1]:
                    count += 1
                if a[i][1] > need_y:
                    need_y = a[i][1]
        if need_y > robot_cord[1]:
            ans += 'U' * (need_y - robot_cord[1])
            robot_cord[1] = need_y
        if count < n:
            robot_cord[0] += 1
            ans += 'R'
            if robot_cord in a:
                count += 1
    if count == n:
        print('YES')
        print(ans)
    else:
        print('NO')


R=lambda:map(int,input().split())
t,=R()
for _ in[0]*t:a=sorted([*R()]for _ in[0]*sum(R()));b=[y for x,y
in a];print(('YES '+''.join('R'*(x-u)+'U'*(y-v)for(u,v),(x,y)in
zip([[0,0]]+a,a)),'NO')[b>sorted(b)])


I=input
for _ in[0]*int(I()):a=sorted([*map(int,I().split())]for _ in[0]*int(I()));b=[y
for x,y in a];print(('YES '+''.join('R'*(x-u)+'U'*(y-v)for(u,v),(x,y)in
zip([[0,0]]+a,a)),'NO')[b>sorted(b)])


t = int(input())
while t > 0:
    n = int(input())
    x = []
    while n > 0:
        x.append(list(map(int, input().split())))
        n -= 1
    x = sorted(x)
    vujs, kotis = [], []
    for xy in x:
        vujs.append(xy[0])
        kotis.append(xy[1])
    if vujs == sorted(vujs) and kotis == sorted(kotis):
        print('YES')
        pos = [0, 0]
        command = ''
        for xy in x:
            while pos[0] != xy[0] and pos[1] != xy[1]:
                pos[0] += 1
                pos[1] += 1
                command += 'RU'
            if pos[0] == xy[0] and pos[1] != xy[1]:
                pos[1] += 1
                command += 'U'
            if pos[1] == xy[1] and pos[0] != xy[0]:
                pos[0] += 1
        print(command)
    else:
        print('NO')
    t -= 1


t = int(input())
while t > 0:
    n = int(input())
    x = []
    while n > 0:
        x.append(list(map(int, input().split())))
        n -= 1
    x = sorted(x)
    print(x)
    vujs, kotis = [], []
    for xy in x:
        vujs.append(xy[0])
        kotis.append(xy[1])
    print(vujs, kotis)
    if vujs == sorted(vujs) and kotis == sorted(kotis):
        print('YES')
        moves = 0
        pos = [0, 0]
        command = ''
        for xy in x:
            while pos[0] != xy[0] and pos[1] != xy[1]:
                pos[0] += 1
                pos[1] += 1
                command += 'RU'
            if pos[0] == xy[0] and pos[1] != xy[1]:
                pos[1] += 1
                command += 'U'
            if pos[1] == xy[1] and pos[0] != xy[0]:
                pos[0] += 1
        print(command)
    else:
        print('NO')
    t -= 1


t = int(input())
while t > 0:
    n = int(input())
    x = []
    while n > 0:
        x.append(list(map(int, input().split())))
        n -= 1
    x = sorted(x)
    vujs, kotis = [], []
    for xy in x:
        vujs.append(xy[0])
        kotis.append(xy[1])
    if vujs == sorted(vujs) and kotis == sorted(kotis):
        print('YES')
        pos = [0, 0]
        command = ''
        for xy in x:
            while pos[0] != xy[0]:
                pos[0] += 1
                command += 'R'
            while pos[1] != xy[1]:
                pos[1] += 1
                command += 'U'
        print(command)
    else:
        print('NO')
    t -= 1


for _ in range(int(input())):
    N = int(input())
    val = ""
    A = []
    for i in range(N):
        x,y = map(int,input().split())
        A.append([x,y])
    A.sort()
    #print(A)
    t = [0,0]
    temp = 0
    for i in range(len(A)):
        if(A[i][0]-t[0]<0 or A[i][1]-t[1]<0):
            print("NO")
            temp = 1
            break
        else:
            z = "R"*(A[i][0]-t[0])
            z+= "U"*(A[i][1]-t[1])
            val+=z
            t[0] = A[i][0]
            t[1] = A[i][1]
    if(temp == 0):
        print(val)


for _ in range(int(input())):
    N = int(input())
    val = ""
    A = []
    for i in range(N):
        x,y = map(int,input().split())
        A.append([x,y])
    A.sort()
    #print(A)
    t = [0,0]
    temp = 0
    for i in range(len(A)):
        if(A[i][0]-t[0]<0 or A[i][1]-t[1]<0):
            print("NO")
            temp = 1
            break
        else:
            z = "R"*(A[i][0]-t[0])
            z+= "U"*(A[i][1]-t[1])
            val+=z
            t[0] = A[i][0]
            t[1] = A[i][1]
    if(temp == 0):
        print("YES")
        print(val)


I = input
pr = print

def dist(x):
	return x[0]**2+x[1]**2

def main():
	for _ in range(int(I())):
		ar=[[0,0,0]];s=[];f=0
		for _ in range(int(I())):
			c=list(map(int,I().split()))
			c.append(dist(c))
			ar.append(c)
		ar.sort(key=dist)
		for i in range(len(ar)-1):
			if ar[i][2]==ar[i+1][2] or (ar[i+1][0]<ar[i][0]) or (ar[i+1][1]<ar[i][1]):pr("NO");f=1;break
			s.append('R'*(ar[i+1][0]-ar[i][0]))
			s.append('U'*(ar[i+1][1]-ar[i][1]))
		if not f:
			pr("YES",''.join(s),sep='\n')
		# pr(ar)

main()


I = input
pr = print

def dist(x):
	return x[0]**2+x[1]**2

def main():
	for _ in range(int(I())):
		ar=[[0,0,0]];s=[];f=0
		for _ in range(int(I())):
			c=list(map(int,I().split()))
			c.append(dist(c))
			ar.append(c)
		ar.sort(key=dist)
		for i in range(len(ar)-1):
			if ar[i][2]==ar[i+1][2]:pr("NO");f=1;break
			s.append('R'*(ar[i+1][0]-ar[i][0]))
			s.append('U'*(ar[i+1][1]-ar[i][1]))
		if not f:
			pr("YES",''.join(s),sep='\n')
		# pr(ar)

main()


t = int(input())
ans_sum = []
for i in range(t):
    n = int(input())
    data = []
    for j in range(n):
        data.append(list(map(int, input().split())))
    data.sort()
    preY = 0
    preX = 0
    ans = []
    for j in range(n):
        ans += ['R'] * (data[j][0] - preX)
        preX = data[j][0]
        if preY > data[j][1]:
            print("NO")
            flag = True
            break
        ans += ["U"] * (data[j][1] - preY)
        preY = data[j][1]
    if not flag:
        print("Yes")
        print("".join(ans))


t = int(input())
for i in range(t):
    n = int(input())
    data = []
    for j in range(n):
        data.append(list(map(int, input().split())))
    data.sort()
    preY = 0
    preX = 0
    ans = []
    for j in range(n):
        ans += ['R'] * (data[j][0] - preX)
        preX = data[j][0]
        if preY > data[j][1]:
            print("NO")
            flag = True
            break
        ans += ["U"] * (data[j][1] - preY)
        preY = data[j][1]
    print("".join(ans))


t = int(input())
ans_sum = []
for i in range(t):
    n = int(input())
    data = []
    for j in range(n):
        data.append(list(map(int, input().split())))
    data.sort()
    preY = 0
    preX = 0
    ans = []
    flag = False
    for j in range(n):
        ans += ['R'] * (data[j][0] - preX)
        preX = data[j][0]
        if preY > data[j][1]:
            print("NO")
            flag = True
            break
        ans += ["U"] * (data[j][1] - preY)
        preY = data[j][1]
    if not flag:
        print("YES")
        print("".join(ans))


n = int(input())
j = []
for i in range(n):
  m = int(input())
  list_point = []
  x_start,y_start = 0,0
  for i in range(m):
    a = [int(a) for a in input().split()]
    a.append(a[0]**2 +a[1]**2)
    list_point.append(a)
  g = sorted(list_point)
  count = 0
  min = g[0][2] - 1
  string = ""
  for i in range(len(g)):
    if g[i][2] > min:
      count += 1
      min = g[i][2]
  if count == len(g):
    j.append("YES")
    for i in range(len(list_point)):
      a = g[i][0]
      b = g[i][1]
      string = string + "R"*(a-x_start) + "U" *(b-y_start)
      x_start = a
      y_start = b
    j.append(string)
  if count != len(g):
    j.append("NO")
for i in range(len(j)):
  print(j[i])


n = int(input())
j = []
for i in range(n):
  m = int(input())
  list_point = []
  x_start,y_start = 0,0
  for i in range(m):
    a = [int(a) for a in input().split()]
    list_point.append(a)
  g = sorted(list_point)
  count = 0
  min = g[0][1]
  string = ""
  for i in range(len(g)):
    if g[i][1] >= min:
      count += 1
      min = g[i][1]
  if count == len(g):
    j.append("YES")
    for i in range(len(list_point)):
      a = g[i][0]
      b = g[i][1]
      string = string + "R"*(a-x_start) + "U" *(b-y_start)
      x_start = a
      y_start = b
    j.append(string)
  if count != len(g):
    j.append("NO")
for i in range(len(j)):
  print(j[i])


#!/bin/python3

import math
import os
import random
import re
import sys

if __name__ == '__main__':
    t =int(input())
    for i in range(t):
        flag = 0
        cod = []

        n = int(input())
        for i in range(n):
            value = input().split()
            l = int(value[0])
            r = int(value[1])
            cod.append([l,r])
        cod = sorted(cod)
        value = cod[0][1]
        for i in range(1,n):
            if value>cod[i][1]:
                print("NO",end="")
                flag = 1
                break
            else:
                value = cod[i][1]
        if flag == 0:
            print("YES")
            print("R"*(cod[0][0]),end="")
            print("U"*(cod[0][1]),end="")
            for i in range(1,n):
                print("R"*(cod[i][0]-cod[i-1][0]),end="")
                print("U"*(cod[i][1]-cod[i-1][1]),end="")
        print("")


#!/bin/python3

import math
import os
import random
import re
import sys

if __name__ == '__main__':
    t =int(input())
    cod = []
    for i in range(t):
        flag = 0
        n = int(input())
        for i in range(n):
            value = input().split()
            l = int(value[0])
            r = int(value[1])
            cod.append([l,r])
        cod = sorted(cod)
        value = cod[0][1]
        for i in range(1,n):
            if value>cod[i][1]:
                print("NO",end="")
                flag = 1
                break
            else:
                value = cod[i][1]
        if flag == 0:
            print("YES")
            print("R"*(cod[0][0]),end="")
            print("U"*(cod[0][1]),end="")
            for i in range(1,n):
                print("R"*(cod[i][0]-cod[i-1][0]),end="")
                print("U"*(cod[i][1]-cod[i-1][1]),end="")
        print("")


#!/bin/python3

import math
import os
import random
import re
import sys

if __name__ == '__main__':
    t =int(input())
    for i in range(t):
        flag = 0
        cod = []

        n = int(input())
        for i in range(n):
            value = input().split()
            l = int(value[0])
            r = int(value[1])
            cod.append([l,r])
        cod = sorted(cod)
        print(cod)
        value = cod[0][1]
        for i in range(1,n):
            if value>cod[i][1]:
                print("NO",end="")
                flag = 1
                break
            else:
                value = cod[i][1]
        if flag == 0:
            print("YES")
            print("R"*(cod[0][0]),end="")
            print("U"*(cod[0][1]),end="")
            for i in range(1,n):
                print("R"*(cod[i][0]-cod[i-1][0]),end="")
                print("U"*(cod[i][1]-cod[i-1][1]),end="")
        print("")


t = int(input())
for _ in range(t):
    n = int(input())
    l = []
    for _ in range(n):
        a,b = map(int,input().split())
        l.append([a,b])
    l.sort()
    st = ""
    px,py=0,0
    flag=1
    cnt=0
    for i in l:
        nx = i[0]-px
        ny = i[1]-py
        if(nx<0 or ny<0):
            print("NO")
            flag=0
            break
        st = st+'R'*nx + 'U'*ny
        px = i[0]
        py = i[1]
        cnt+=1

    if(flag==0):
        continue
    if(cnt==n):
        print("YES")
        print(st)
    else:
        print("NO")


t = int(input())
for _ in range(t):
    n = int(input())
    l = []
    for _ in range(n):
        a,b = map(int,input().split())
        l.append([a,b])
    l.sort()
    st = ""
    st2 = ""
    px,py=0,0
    flag=1
    for i in l:
        nx = i[0]-px
        ny = i[1]-py
        if(nx<0 or ny<0):
            print("NO")
            flag=0
            continue
        st = st+'R'*nx + 'U'*ny
        st2 = st2+'U'*ny + 'R'*nx
        px = i[0]
        py = i[1]

    if(flag==1):
        print("YES")
        if(st<st2):
            print(st)
        else:
            print(st2)


t = int(input())
for _ in range(t):
    n = int(input())
    l = []
    for _ in range(n):
        a,b = map(int,input().split())
        l.append([a,b])
    l.sort()
    st = ""
    px,py=0,0
    flag=1
    for i in l:
        nx = i[0]-px
        ny = i[1]-py
        if(nx<0 or ny<0):
            print("NO")
            flag=0
            continue
        st = st+'R'*nx + 'U'*ny
        px = i[0]
        py = i[1]
    if(flag==1):
        print("YES")
        print(st)


t = int(input())
for _ in range(t):
    n = int(input())
    l = []
    for _ in range(n):
        a,b = map(int,input().split())
        l.append([a,b])
    l.sort()
    st = ""
    px,py=0,0
    flag=1
    cnt=0
    for i in l:
        nx = i[0]-px
        ny = i[1]-py
        if(nx<0 or ny<0):
            print("NO")
            flag=0
            break
        st = st+'R'*nx + 'U'*ny
        px = i[0]
        py = i[1]
        cnt+=1

    if(flag==1 and cnt==n):
        print("YES")
        print(st)
    else:
        print("NO")


t=int(input())
for i in range(t):
  n=int(input())
  a=[[0,0]]
  for j in range(n):
    x=list(map(int, input().split()))
    a.append(x)
  a.sort()

  s=""

  for i in range(len(a)-1):
    if (a[i+1][0]-a[i][0])<0 or (a[i+1][1]-a[i][1])<0:
      s="NO"
      break;
    else:
      s=s+(a[i+1][0]-a[i][0])*'R'
      s=s+(a[i+1][1]-a[i][1])*'U'
  print(s)


t=int(input())
for i in range(t):
    n=int(input())
    a=[[0,0]]
    for j in range(n):
        x=list(map(int, input().split()))
        a.append(x)
    a.sort()

    s=""

    for i in range(len(a)-1):
        if (a[i+1][0]-a[i][0])<0 or (a[i+1][1]-a[i][1])<0:
            s="NO"
            break;
        else:
            s=s+(a[i+1][0]-a[i][0])*'R'
            s=s+(a[i+1][1]-a[i][1])*'U'

    if s=="NO":
        print(s)
    else:
        print("YES")
        print(s)


a=[]
for i in range(int(input())):
    for j in range(int(input())):
        m,n=map(int,input().split())
        a.append((m,n))
    flag=0;x=0;y=0;s=""
    for k,l in sorted(a):
        p=k-x
        q=l-y
        if p>=0 and q>=0:
            s=s+'R'*p+'U'*q
            x=k;y=l
        else:
            print("NO")
            flag=1
            break
    x=0;y=0
    a.clear()
    if flag!=1:
        print("YES")
        print(s)


def felement(b):
    return(b[0])
q=int(input())
for l in range(q):
    t=int(input())
    a=[[0,0]]
    st=[]
    j=0
    for i in range(t):
        row=list(map(int,input().split()))
        a.append(row)
    a.sort(key=felement)
    k=0
    for i in range(t):
        if(a[i][1]>a[i+1][1]):
            k=1
            break
        else:
            n=a[i+1][0]-a[i][0]
            while(n):
                st.append("R")
                j=j+1
                n=n-1
            n=a[i+1][1]-a[i][1]
            while(n):
                st.append("U")
                j=j+1
                n=n-1
    if(k==1):
        print("NO")
    else:
        print("YES")
        i=0
        while(i<j):
            print(st[i],end="")
            i=i+1
        print()


def felement(b):
    return(b[0])
q=int(input())
for l in range(q):
    t=int(input())
    a=[[0,0]]
    st=[]
    j=0
    for i in range(t):
        row=list(map(int,input().split()))
        a.append(row)
    a.sort(key=felement)
    k=0
    for i in range(t):
        if(a[i][1]>a[i+1][1]):
            k=1
            break
        else:
            n=a[i+1][0]-a[i][0]
            while(n):
                st.append("R")
                j=j+1
                n=n-1
            n=a[i+1][1]-a[i][1]
            while(n):
                st.append("U")
                j=j+1
                n=n-1
    if(k==1):
        print("NO")
    else:
        print("YES")
        i=0
        while(i<j):
            print(st[i],end="")
            i=i+1


def felement(b):
    return(b[0])
ff=[]
r=0
q=int(input())
for l in range(q):
    t=int(input())
    a=[[0,0]]
    st=[]
    j=0
    for i in range(t):
        row=list(map(int,input().split()))
        a.append(row)
    a.sort(key=felement)
    k=0
    for i in range(t):
        if(a[i][1]>a[i+1][1]):
            k=1
            break
        else:
            n=a[i+1][0]-a[i][0]
            while(n):
                st.append("R")
                j=j+1
                n=n-1
            n=a[i+1][1]-a[i][1]
            while(n):
                st.append("U")
                j=j+1
                n=n-1
    if(k==1):
        ff.append("NO")
        r=r+1
    else:
        ff.append("YES")
        r=r+1
        i=0
        bb=""
        while(i<j):
            bb=bb+st[i]
            i=i+1
        ff.append(bb)
        r=r+1
i=0
while(i<r):
    print(ff[i])
    i=i+1


def felement(b):
    return(b[0])
q=int(input().split())
for l in range(q):
    t=int(input())
    a=[[0,0]]
    st=[]
    j=0
    for i in range(t):
        row=list(map(int,input().split()))
        a.append(row)
    a.sort(key=felement)
    k=0
    for i in range(t):
        if(a[i][1]>a[i+1][1]):
            k=1
            break
        else:
            n=a[i+1][0]-a[i][0]
            while(n):
                st.append("R")
                j=j+1
                n=n-1
            n=a[i+1][1]-a[i][1]
            while(n):
                st.append("U")
                j=j+1
                n=n-1
    if(k==1):
        print("NO")
    else:
        print("YES")
        i=0
        while(i<j):
            print(st[i],end="")
            i=i+1


def felement(b):
    return(b[0])
t=int(input())
a=[[0,0]]
st=[]
j=0
for i in range(t):
     row=list(map(int,input().split()))
     a.append(row)
a.sort(key=felement)
k=0
for i in range(t):
    if(a[i][1]>a[i+1][1]):
        k=1
        break
    else:
        n=a[i+1][0]-a[i][0]
        while(n):
            st.append("R")
            j=j+1
            n=n-1
        n=a[i+1][1]-a[i][1]
        while(n):
            st.append("U")
            j=j+1
            n=n-1
if(k==1):
    print("NO")
else:
    print("YES")
    i=0
    while(i<j):
        print(st[i],end="")
        i=i+1


for iten in [0]*int(input()):
  n = int(input())
  lis = [list(map(int,input().split())) for _ in range(n)]
  lis.sort()
  b= [i[1] for i in lis]
  if b !=sorted(b):
    print('NO')
    continue
  lis,res = [[0,0]]+lis,''
  for i in range(1,n+1):
      res += "R" * (lis[i][0] - lis[i - 1][0])
      res += "U" * (lis[i][1] - lis[i - 1][1])
  print('YES')
  print(res)


for iten in [0]*int(input()):
  n = int(input())
  lis = [list(map(int,input().split())) for _ in range(n)]
  lis.sort()
  b= [i[1] for i in lis]
  if b !=sorted(b):
    print('NO')
    continue
  lis,res = [[0,0]]+lis,''
  for i in range(1,n+1):
      res += "R" * (lst[i][0] - lst[i - 1][0])
      res += "U" * (lst[i][1] - lst[i - 1][1])
  print('YES')
  print(res)


t = int(input())
v = 1
b = ""
va_a_decir = []

while v <= t:
    b = ""
    robotito = [0, 0]
    d = {}
    e = {}
    ord = []
    estado = "idle"
    c = int(input())

    for i in range(0, c):
        a = input()
        d[i] = a
        x = int(d[i].split(" ")[0])
        y = int(d[i].split(" ")[1])
        e[x**2+y**2] = x, y

    e = sorted()
    for i in e:
        if e[i] not in ord:
            ord.append(e[i])
    for i in range(0, len(ord)):
        if int(ord[i].split(" ")[0]) or robotito[1] > int(ord[i].split(" ")[1]) < 0:
            estado = "NO"
        if estado != "NO":
            while robotito[0] < int(ord[i].split(" ")[0]):
                robotito[0] += 1
                b += "R"
            while robotito[1] < int(ord[i].split(" ")[1]):
                robotito[1] += 1
                b += "U"
        if robotito[0] > int(ord[i].split(" ")[0]) or robotito[1] > int(ord[i].split(" ")[1]):
            b = ""
            estado = "NO"

    if estado != "NO":
        va_a_decir.append("YES")
        va_a_decir.append(b)
    if estado == "NO":
        va_a_decir.append("NO")

    v += 1

for i in range(0, len(va_a_decir)):
    print(va_a_decir[i])

return 0


t = int(input())
v = 1
b = ""
va_a_decir = []

while v <= t:
    b = ""
    robotito = [0, 0]
    d = {}
    genial = []
    ord_rep = []
    ord = []
    estado = "idle"
    c = int(input())

    for i in range(0, c):
        a = input()
        d[i] = a
        x = int(d[i].split(" ")[0])
        y = int(d[i].split(" ")[1])
        genial.append(x**2+y**2)

    genial.sort()
    for i in range(0, len(genial)):
        for k in range(0, len(d)):
            if genial[i] == (int(d[k].split(" ")[0])**2 + int(d[k].split(" ")[1])**2):
                ord_rep.append(d[k])

    for i in ord_rep:
            if i not in ord:
                ord.append(i)
    for i in range(0, len(ord)):
        if estado != "NO":
            while robotito[0] < int(ord[i].split(" ")[0]):
                robotito[0] += 1
                b += "R"
            while robotito[1] < int(ord[i].split(" ")[1]):
                robotito[1] += 1
                b += "U"
        if robotito[0] > int(ord[i].split(" ")[0]) or robotito[1] > int(ord[i].split(" ")[1]):
            b = ""
            estado = "NO"

    if estado != "NO":
        va_a_decir.append("YES")
        va_a_decir.append(b)
    if estado == "NO":
        va_a_decir.append("NO")

    estado = "idle"
    robotito = [0, 0]
    v += 1

for i in range(0, len(va_a_decir)):
    print(va_a_decir[i])


t = int(input())
v = 1
b = ""
va_a_decir = []
while v <= t:
    robotito = [0,0]
    def U():
        robotito[1] += 1
    def R():
        robotito[0] += 1
    Puede = "idle"
    d = {}
    genial = []
    ord_rep = []
    ord = []
    for i in range(0, t):
        c = int(input())
        dis = []
        piola = []
        robotito = [0,0]

        for i in range(0, c):
            a = input()
            d[i] = a

        for i in range(0, c):
            for k in range(0, c):
                if d[i].split(" ")[0] > d[k].split(" ")[0]:
                    if d[i].split(" ")[1] < d[k].split(" ")[1]:
                        Puede = "NO"
                if int(d[i].split(" ")[0]) < 0:
                    Puede = "NO"
                if int(d[i].split(" ")[1]) < 0:
                    Puede = "NO"
                if Puede != "NO":
                    Puede = "YES"
                    x = int(d[i].split(" ")[0])
                    y = int(d[i].split(" ")[1])
                    genial.append(x**2+y**2)

        genial.sort()
        if Puede == "NO":
            va_a_decir.append("NO")
        if Puede != "NO":
            for i in range(0, len(genial)):
                j = []
                for k in range(0,len(d)):
                    if genial[i] == (int(d[k].split(" ")[0])**2 + int(d[k].split(" ")[1])**2):
                        ord_rep.append(d[k])

            for i in ord_rep:
                if i not in ord:
                    ord.append(i)

            for i in range(0, len(ord)):

                while robotito[0] < int(ord[i].split(" ")[0]):
                    R()
                    j.append("R")

                while robotito[1] < int(ord[i].split(" ")[1]):
                    U()
                    j.append("U")

            for i in range(0, len(j)):
                b += str(j[i])

            va_a_decir.append("YES")
            va_a_decir.append(b)
        b = ""
        robotito = [0, 0]
        Puede = "idle"
        d = {}
        genial = []
        ord_rep = []
        ord = []
        v += 1
    for i in range(0,len(va_a_decir)):
        print(va_a_decir[i])


t = int(input())
v = 1
b = ""
va_a_decir = []
while v <= t:
    robotito = [0, 0]
    Puede = "idle"
    d = {}
    genial = []
    ord_rep = []
    ord = []
    for i in range(0, t):
        c = int(input())
        dis = []
        piola = []
        robotito = [0, 0]

        for i in range(0, c):
            a = input()
            d[i] = a
        if Puede != "NO":
            for i in range(0, c):
                for k in range(0, c):
                    if d[i].split(" ")[0] > d[k].split(" ")[0]:
                        if d[i].split(" ")[1] < d[k].split(" ")[1]:
                            Puede = "NO"
                    if int(d[i].split(" ")[0]) < 0:
                        Puede = "NO"
                    if int(d[i].split(" ")[1]) < 0:
                        Puede = "NO"
                    if Puede != "NO":
                        Puede = "YES"
                        x = int(d[i].split(" ")[0])
                        y = int(d[i].split(" ")[1])
                        genial.append(x**2+y**2)

        genial.sort()
        if Puede == "NO":
            va_a_decir.append("NO")
        if Puede != "NO":
            for i in range(0, len(genial)):
                j = []
                for k in range(0,len(d)):
                    if genial[i] == (int(d[k].split(" ")[0])**2 + int(d[k].split(" ")[1])**2):
                        ord_rep.append(d[k])

            for i in ord_rep:
                if i not in ord:
                    ord.append(i)

            for i in range(0, len(ord)):

                while robotito[0] < int(ord[i].split(" ")[0]):
                    robotito[0] += 1
                    j.append("R")

                while robotito[1] < int(ord[i].split(" ")[1]):
                    robotito[1] += 1
                    j.append("U")

            for i in range(0, len(j)):
                b += str(j[i])

            va_a_decir.append("YES")
            va_a_decir.append(b)
        b = ""
        robotito = [0, 0]
        Puede = "idle"
        d = {}
        genial = []
        ord_rep = []
        ord = []
        v += 1
    for i in range(0,len(va_a_decir)):
        print(va_a_decir[i])


t = int(input())
v = 1
b = ""
va_a_decir = []
def mayor(elem):
    return int(elem.split(" ")[0]) + int(elem.split(" ")[1])

while v <= t:
    b = ""
    robotito = [0, 0]
    ord = []
    estado = "idle"
    c = int(input())

    for i in range(0, c):
        a = input()
        ord.append(a)

    ord.sort(key=mayor)
    for i in range(0, len(ord)):
        if robotito[0] > int(ord[i].split(" ")[0]) or robotito[1] > int(ord[i].split(" ")[1]) < 0:
            estado = "NO"
            print(robotito)
        if estado != "NO":
            while robotito[0] < int(ord[i].split(" ")[0]):
                robotito[0] += 1
                b += "R"
            while robotito[1] < int(ord[i].split(" ")[1]):
                robotito[1] += 1
                b += "U"
        if robotito[0] > int(ord[i].split(" ")[0]) or robotito[1] > int(ord[i].split(" ")[1]):
            b = ""
            estado = "NO"

    if estado != "NO":
        va_a_decir.append("YES")
        va_a_decir.append(b)
    if estado == "NO":
        va_a_decir.append("NO")

    estado = "idle"
    robotito = [0, 0]
    v += 1

for i in range(0, len(va_a_decir)):
    print(va_a_decir[i])


t = int(input())
v = 1
b = ""
va_a_decir = []
while v <= t:
    robotito = [0, 0]
    Puede = "idle"
    d = {}
    genial = []
    ord_rep = []
    ord = []
    for i in range(0, t):
        c = int(input())
        dis = []
        piola = []
        robotito = [0, 0]

        for i in range(0, c):
            a = input()
            d[i] = a
        if Puede != "NO":
            for i in range(0, c):
                for k in range(i, c):
                    if d[i].split(" ")[0] > d[k].split(" ")[0]:
                        if d[i].split(" ")[1] < d[k].split(" ")[1]:
                            Puede = "NO"
                    if int(d[i].split(" ")[0]) < 0:
                        Puede = "NO"
                    if int(d[i].split(" ")[1]) < 0:
                        Puede = "NO"
                    if Puede != "NO":
                        Puede = "YES"
                        x = int(d[i].split(" ")[0])
                        y = int(d[i].split(" ")[1])
                        genial.append(x**2+y**2)

        genial.sort()
        if Puede == "NO":
            va_a_decir.append("NO")
        if Puede != "NO":
            for i in range(0, len(genial)):
                j = []
                for k in range(0,len(d)):
                    if genial[i] == (int(d[k].split(" ")[0])**2 + int(d[k].split(" ")[1])**2):
                        ord_rep.append(d[k])

            for i in ord_rep:
                if i not in ord:
                    ord.append(i)

            for i in range(0, len(ord)):

                while robotito[0] < int(ord[i].split(" ")[0]):
                    robotito[0] += 1
                    j.append("R")

                while robotito[1] < int(ord[i].split(" ")[1]):
                    robotito[1] += 1
                    j.append("U")

            for i in range(0, len(j)):
                b += str(j[i])

            va_a_decir.append("YES")
            va_a_decir.append(b)
        b = ""
        robotito = [0, 0]
        Puede = "idle"
        d = {}
        genial = []
        ord_rep = []
        ord = []
        v += 1
    for i in range(0,len(va_a_decir)):
        print(va_a_decir[i])


t = int(input())
v = 1
b = ""
va_a_decir = []

while v <= t:
    b = ""
    robotito = [0, 0]
    d = {}
    e = {}
    ord = []
    estado = "idle"
    c = int(input())

    for i in range(0, c):
        a = input()
        d[i] = a
        x = int(d[i].split(" ")[0])
        y = int(d[i].split(" ")[1])
        e[x**2+y**2] = x, y

    e = sorted()
    for i in e:
        if e[i] not in ord:
            ord.append(e[i])

    for i in range(0, len(ord)):
        if estado != "NO":
            while robotito[0] < int(ord[i].split(" ")[0]):
                robotito[0] += 1
                b += "R"
            while robotito[1] < int(ord[i].split(" ")[1]):
                robotito[1] += 1
                b += "U"
        if robotito[0] > int(ord[i].split(" ")[0]) or robotito[1] > int(ord[i].split(" ")[1]):
            b = ""
            estado = "NO"

    if estado != "NO":
        va_a_decir.append("YES")
        va_a_decir.append(b)
    if estado == "NO":
        va_a_decir.append("NO")

    estado = "idle"
    robotito = [0, 0]
    v += 1

for i in range(0, len(va_a_decir)):
    print(va_a_decir[i])


t = int(input())
v = 1
b = ""
va_a_decir = []

while v <= t:
    b = ""
    robotito = [0, 0]
    d = {}
    genial = []
    ord_rep = []
    ord = []
    estado = "idle"
    c = int(input())

    for i in range(0, c):
        a = input()
        d[i] = a
        x = int(d[i].split(" ")[0])
        y = int(d[i].split(" ")[1])
        genial.append(x+y)

    genial.sort()
    for i in range(0, len(genial)):
        for k in range(i, len(d)):
            if genial[i] == (int(d[k].split(" ")[0]) + int(d[k].split(" ")[1])):
                ord_rep.append(d[k])

    for i in ord_rep:
            if i not in ord:
                ord.append(i)
    for i in range(0, len(ord)):
        if robotito[0] > int(ord[i].split(" ")[0]) or robotito[1] > int(ord[i].split(" ")[1]) < 0:
            estado = "NO"
        if estado != "NO":
            while robotito[0] < int(ord[i].split(" ")[0]):
                robotito[0] += 1
                b += "R"
            while robotito[1] < int(ord[i].split(" ")[1]):
                robotito[1] += 1
                b += "U"
        if robotito[0] > int(ord[i].split(" ")[0]) or robotito[1] > int(ord[i].split(" ")[1]):
            b = ""
            estado = "NO"

    if estado != "NO":
        va_a_decir.append("YES")
        va_a_decir.append(b)
    if estado == "NO":
        va_a_decir.append("NO")

    v += 1

for i in range(0, len(va_a_decir)):
    print(va_a_decir[i])


t = int(input())
v = 1
b = ""
va_a_decir = []

while v <= t:
    b = ""
    robotito = [0, 0]
    d = {}
    genial = []
    ord_rep = []
    ord = []
    estado = "idle"
    c = int(input())

    for i in range(0, c):
        a = input()
        d[i] = a
        x = int(d[i].split(" ")[0])
        y = int(d[i].split(" ")[1])
        genial.append(x+y)

    genial.sort()
    for i in range(0, len(genial)):
        for k in range(0, len(d)):
            if genial[i] == (int(d[k].split(" ")[0]) + int(d[k].split(" ")[1])):
                ord_rep.append(d[k])

    for i in ord_rep:
            if i not in ord:
                ord.append(i)
    for i in range(0, len(ord)):
        if robotito[0] > int(ord[i].split(" ")[0]) or robotito[1] > int(ord[i].split(" ")[1]) < 0:
            estado = "NO"
        if estado != "NO":
            while robotito[0] < int(ord[i].split(" ")[0]):
                robotito[0] += 1
                b += "R"
            while robotito[1] < int(ord[i].split(" ")[1]):
                robotito[1] += 1
                b += "U"
        if robotito[0] > int(ord[i].split(" ")[0]) or robotito[1] > int(ord[i].split(" ")[1]):
            b = ""
            estado = "NO"

    if estado != "NO":
        va_a_decir.append("YES")
        va_a_decir.append(b)
    if estado == "NO":
        va_a_decir.append("NO")

    estado = "idle"
    robotito = [0, 0]
    v += 1

for i in range(0, len(va_a_decir)):
    print(va_a_decir[i])


t = int(input())
v = 1
b = ""
va_a_decir = []
def mayor(elem):
    return int(elem.split(" ")[0]) + int(elem.split(" ")[1])

while v <= t:
    b = ""
    robotito = [0, 0]
    ord = []
    estado = "idle"
    c = int(input())

    for i in range(0, c):
        a = input()
        ord.append(a)

    ord.sort(key=mayor)
    for i in range(0, len(ord)):
        if robotito[0] > int(ord[i].split(" ")[0]) or robotito[1] > int(ord[i].split(" ")[1]) < 0:
            estado = "NO"
        if estado != "NO":
            while robotito[0] < int(ord[i].split(" ")[0]):
                robotito[0] += 1
                b += "R"
            while robotito[1] < int(ord[i].split(" ")[1]):
                robotito[1] += 1
                b += "U"
        if robotito[0] > int(ord[i].split(" ")[0]) or robotito[1] > int(ord[i].split(" ")[1]):
            b = ""
            estado = "NO"

    if estado != "NO":
        va_a_decir.append("YES")
        va_a_decir.append(b)
    if estado == "NO":
        va_a_decir.append("NO")

    estado = "idle"
    robotito = [0, 0]
    v += 1

for i in range(0, len(va_a_decir)):
    print(va_a_decir[i])


t = int(input())
v = 1
b = ""
va_a_decir = []
def mayor(elem):
    return elem.split(" ")[0] + elem.split(" ")[1]

while v <= t:
    b = ""
    robotito = [0, 0]
    ord = []
    estado = "idle"
    c = int(input())

    for i in range(0, c):
        a = input()
        ord.append(a)

    ord.sort(key=mayor)

    for i in range(0, len(ord)):
        if robotito[0] > int(ord[i].split(" ")[0]) or robotito[1] > int(ord[i].split(" ")[1]) < 0:
            estado = "NO"
        if estado != "NO":
            while robotito[0] < int(ord[i].split(" ")[0]):
                robotito[0] += 1
                b += "R"
            while robotito[1] < int(ord[i].split(" ")[1]):
                robotito[1] += 1
                b += "U"
        if robotito[0] > int(ord[i].split(" ")[0]) or robotito[1] > int(ord[i].split(" ")[1]):
            b = ""
            estado = "NO"

    if estado != "NO":
        va_a_decir.append("YES")
        va_a_decir.append(b)
    if estado == "NO":
        va_a_decir.append("NO")

    estado = "idle"
    robotito = [0, 0]
    v += 1

for i in range(0, len(va_a_decir)):
    print(va_a_decir[i])


t = int(input())
v = 1
b = ""
va_a_decir = []

while v <= t:
    b = ""
    robotito = [0, 0]
    d = {}
    e = {}
    genial = []
    ord_rep = []
    ord = []
    estado = "idle"
    c = int(input())

    for i in range(0, c):
        a = input()
        d[i] = a
        x = int(d[i].split(" ")[0])
        y = int(d[i].split(" ")[1])
        e[x**2+y**2] = x, y

    e = sorted()
    for i in e:
        if e[i] not in ord:
            ord.append(e[i])

    for i in range(0, len(ord)):
        if estado != "NO":
            while robotito[0] < int(ord[i].split(" ")[0]):
                robotito[0] += 1
                b += "R"
            while robotito[1] < int(ord[i].split(" ")[1]):
                robotito[1] += 1
                b += "U"
        if robotito[0] > int(ord[i].split(" ")[0]) or robotito[1] > int(ord[i].split(" ")[1]):
            b = ""
            estado = "NO"

    if estado != "NO":
        va_a_decir.append("YES")
        va_a_decir.append(b)
    if estado == "NO":
        va_a_decir.append("NO")

    estado = "idle"
    robotito = [0, 0]
    v += 1

for i in range(0, len(va_a_decir)):
    print(va_a_decir[i])


def solution():
    _range, _int, _tuple, _max, _set, _sorted, _min = range, int, tuple, max, set, sorted, min
    from sys import stdout, stdin
    _input, _print = stdin.readline, stdout.write
    for _ in _range(_int(_input())):
        n = _int(_input())
        from collections import defaultdict
        arr = defaultdict(_set)
        for _ in _range(n):
            x, y = [_int(i) for i in _input().split()]
            arr[x].add(y)
        ret_str = ''
        x, y = 0, 0
        # {1: {2, 3}, 3: {3}, 5: {5}, 4: {3}}
        f = True
        for i in _sorted(arr.keys()):
            ret_str += "R"*(i-x)
            x = i
            if y > _min(arr[i]):
                _print("NO\n")
                f = False
                break
            ret_str += "U"*(_max(arr[i])-y)
            y = _max(arr[i])
        if f:
            _print("YES\n"+ret_str+"\n")
solution()


def solution():
    _range, _int, _tuple, _max = range, int, tuple, max
    from sys import stdout, stdin
    _input, _print = stdin.readline, stdout.write
    for _ in _range(_int(_input())):
        n = _int(_input())
        from collections import defaultdict
        arr = defaultdict(set)
        for _ in range(n):
            x, y = [int(i) for i in input().split()]
            arr[x].add(y)
        ret_str = ''
        x, y = 0, 0
        # {1: {2, 3}, 3: {3}, 5: {5}, 4: {3}}
        f = True
        for i in sorted(arr.keys()):
            ret_str += "R"*(i-x)
            x = i
            if y > min(arr[i]):
                _print("NO\n")
                f = False
                break
            ret_str += "U"*(max(arr[i])-y)
            y = max(arr[i])
        if f:
            _print("YES\n"+ret_str+"\n")
solution()