///        Saniuzzaman Robin           ///
///        CSE'08, Comilla University  ///

#include<bits/stdc++.h>
using namespace std;

/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;*/

/*--------------------------Containers------------------------*/
typedef     long long int           ll;
typedef     unsigned long long int  ull;
typedef     vector < int >          vi;
typedef     vector < ll >           vll;
typedef     vector < vi >           vvi;
typedef     pair< int,int >         pi;
typedef     pair< ll, ll >          pll;
typedef     vector< pi >            vpi;
typedef     vector< pll >           vpll;
/*------------------------------------------------------------*/

/*--------------------------Limits & Constants----------------*/
#define     MAX                 200007
#define     MOD                 ll(1e9+7)
#define     INF                 ll(8230219982008199610)
#define     MINF                ll(-8230219982008199610)
#define     IL                  INT_MAX-10000
#define     MIL                 INT_MIN+10000
#define     PI                  2*acos(0.0)
/*------------------------------------------------------------*/

/*--------------------------Macros----------------------------*/
#define     fast                ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define     pf                  printf
#define     sc                  scanf
#define     all(a)              (a).begin(),(a).end()
#define     sz(x)               int(x.size())
#define     pb                  push_back
#define     eb                  emplace_back
#define     mp                  make_pair
#define     ff                  first
#define     ss                  second
#define     mem(a,n)            memset(a, n, sizeof(a) )
#define     gcd(a,b)            __gcd(a,b)
#define     lcm(a,b)            (a*(b/gcd(a,b)))
#define     unik(v)             v.resize(distance(v.begin(),unique(all(v))))
/*------------------------------------------------------------*/

/*----------------------Scans and Prints----------------------*/

#define     print(a,n)          for(int pr = 0; pr<int(n); pr++)cout<<a[pr]<<" ";cout<<endl
#define     printa(x)           cout<<x<<endl;
#define     debug               cout<<" OK "<<endl
///#define     endl                "\n"
/*------------------------------------------------------------*/


/*------------------------Graph Moves-------------------------*/
//const int dx[]= {+1,-1,+0,+0};
//const int dy[]= {+0,+0,+1,-1};
//const int dx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int dy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int dx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int dy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------------------*/


/*------------------------Bitmask-----------------------------*/
//int Set(int N,int pos){return N = (N or(1<<pos));}
//int reset(int N,int pos){return N = (N and ~(1<<pos));}
//bool check(int N,int pos){return (bool)(N and (1<<pos));}
/*------------------------------------------------------------*/


///void Sieve(int n){bool prime[n+1];memset(prime,true,sizeof(prime));for(int p=2; p*p<=n; p++){if(prime[p]==true){for(int i=p*p; i<=n;i+= p)prime[i] = false;}}}
///ll POW(ll a, ll b){ll res = 1;while (b > 0){if (b & 1)res = res * a;a = a * a;b >>= 1;}return res;}
///ll bigmod(ll a, ll b, ll m){a%=m;ll res=1;while(b>0){if(b&1)res=res*a%m;a=a*a%m;b>>=1;}return res;}
///ll INV(ll a,ll m){return bigmod(a,m-2,m);}
///int phi[500007];void phi(int N){for(int i=2; i<=N; i++)phi[i] = i;for(int i =2; i<=N; i++){if(phi[i]==i){for(int j=i; j<=N; j+=i)phi[j]-=phi[j]/i;}}}
///ll nCr[1001][1001]={0};void initialize(){nCr[0][0]=1;for(int i=1; i<1001;i++){nCr[i][0]=1;for(int j=1;j<i+1;j++){nCr[i][j]=(nCr[i-1][j-1]+nCr[i-1][j]);}}}



int main()
{

    //freopen("input1.txt", "r", stdin);
    int q;
    cin>>q;
    while(q--)
    {
       string s;
       cin>>s;
       int ln = s.length();
       vpi v;
       int x = 0, y = 0;
       for(int i=0; i<ln; i++)
       {
            if(s[i]=='L')
                x--;
            else if(s[i]=='R')
                x++;
            else if(s[i]=='U')
                y++;
            else
                y--;
            if(x or y)
                v.pb(mp(x,y));
       }
       int ok = 0, crrx, crry, addx, addy;
       for(int i=0; i<v.size(); i++)
        {
            x = y = 0;
            crrx = v[i].ff, crry = v[i].ss;
            for(int j=0; j<ln; j++)
            {
                addx = 0, addy = 0;
                if(s[j]=='L')
                    addx--;
                else if(s[j]=='R')
                    addx++;
                else if(s[j]=='U')
                    addy++;
                else
                    addy--;
                if(x+addx!=crrx or y+addy!=crry)
                {
                    x+=addx;
                    y+=addy;
                }
            }
            if(x==0 and y==0)
            {
                ok = 1;
                break;
            }
        }
        if(ok)
            cout<<crrx<<" "<<crry<<endl;
        else
            cout<<"0 0"<<endl;

    }



    return 0;
}