44*/
55#include < bits/stdc++.h>
66using namespace std ;
7- typedef long long ll ;
8- typedef vector<ll> vl;
9- typedef vector<bool > vb;
10- typedef vector<char > vc;
11- typedef map<ll,ll> ml;
12- typedef set<char >sc;
13- typedef set<ll> sl;
14- #define pan cin.tie(0 );cout.tie(0 );ios_base::sync_with_stdio(0 );
15- // define values.
16- #define mod 10000009
17- #define phi 1.618
18- /* Bit-Stuff */
19- #define get_set_bits (a ) (__builtin_popcount(a))
20- #define get_set_bitsll (a ) ( __builtin_popcountll(a))
21- #define get_trail_zero (a ) (__builtin_ctz(a))
22- #define get_lead_zero (a ) (__builtin_clz(a))
23- #define get_parity (a ) (__builtin_parity(a))
24- /* Abbrevations */
25- #define ff first
26- #define ss second
27- #define mp make_pair
28- #define line cout<<endl;
29- #define pb push_back
30- #define Endl " \n "
31- // loops
32- #define forin (arr,n ) for (ll i=0 ;i<n;i++) cin>>arr[i];
33- // Some print
34- #define no cout<<" NO" <<endl;
35- #define yes cout<<" YES" <<endl;
36- #define cc ll test;cin>>test;while (test--)
37- // sort
38- #define all (V ) (V).begin(),(V).end()
39- #define srt (V ) sort(all(V))
40- #define srtGreat (V ) sort(all(V),greater<ll>())
41- // function
7+ typedef long long ll;
428
43- ll power (ll x,ll y )
9+ int solve ( )
4410{
45- ll res=1 ;
46- // x=x%mod;
47- while (y>0 )
11+ string s;
12+ cin >> s;
13+ map<char , ll> m;
14+ for (auto x : s)
4815 {
49- if (y%2 ==1 )
50- {
51- res*=x;
52- // res=res%mod;
53- }
54- y/=2 ; x*=x; // x=x%mod;
16+ m[x]++;
5517 }
56- return res;
57- }
58- /* ascii value
59- A=65,Z=90,a=97,z=122
60- */
61- /* -----------------------------------------------------------------------------------*/
6218
19+ ll minUD = min (m[' U' ], m[' D' ]);
20+ ll minLR = min (m[' L' ], m[' R' ]);
6321
64- ll solve ()
65- {
66- string s;
67- cin>>s;
68- map<char ,ll> m;
69- for (auto x:s)
70- m[x]++;
71- ll temp1=min (m[' U' ],m[' D' ]);
72- ll temp2=min (m[' L' ],m[' R' ]);
73- if (temp1==0 &&temp2==0 )
22+ if (minUD == 0 && minLR == 0 )
7423 {
75- cout<< 0 << endl;
76- cout<< " " << endl;
24+ cout << 0 << endl;
25+ cout << " " << endl;
7726 }
78- else if (temp1== 0 )
27+ else if (minUD == 0 )
7928 {
80- if (temp2>=1 )
81- {
82- cout<<2 <<endl<<" LR" <<endl;
83- }
84- else
85- {
86- cout<<0 <<endl<<" " <<endl;
87- }
29+ cout << 2 << endl
30+ << " LR" << endl;
8831 }
89- else if (temp2== 0 )
32+ else if (minLR == 0 )
9033 {
91- if (temp1>=1 )
92- {
93- cout<<2 <<endl<<" UD" <<endl;
94- }
34+ cout << 2 << endl
35+ << " UD" << endl;
9536 }
9637 else
9738 {
98- string s=" " ;
99- for (ll i=0 ;i<temp1;i++)
39+ string s = " " ;
40+ for (ll i = 0 ; i < minUD; i++)
41+ {
42+ s += ' U' ;
43+ }
44+ for (ll i = 0 ; i < minLR; i++)
10045 {
101- s+= ' U ' ;
46+ s += ' R ' ;
10247 }
103- for (ll i=0 ;i<temp2;i++)
104- s+=' R' ;
105- for (ll i=0 ;i<temp1;i++)
106- s+=' D' ;
107- for (ll i=0 ;i<temp2;i++)
108- s+=' L' ;
109- cout<<s.size ()<<endl<<s<<endl;
48+ s += string (minUD, ' D' );
49+ s += string (minLR, ' L' );
50+
51+ cout << s.size () << endl
52+ << s << endl;
11053 }
11154 return 0 ;
11255}
113-
11456int main ()
11557{
116- // freopen("input.txt"a, "r", stdin);
117- pan;
118- // solve();
119- cc
58+ int testCase = 1 ;
59+ cin >> testCase;
60+ while (testCase--)
12061 {
12162 solve ();
12263 }
123- }
64+ return 0 ;
65+ }
0 commit comments