
#include<bits/stdc++.h>

#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define SPEED ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sz size()
#define all(x) x.begin(),x.end()
#define OO 1e18
#define iOO INT_MAX
#define Mdp memset(Dp,-1,sizeof Dp)
#define R return
#define Test int TT;cin>>TT;for(int T=1;T<=TT;T++)
using namespace std;
const int N = 200010;
string s;

pii Calc(char c)
{
    if(c == 'L')
    {
        R {-1,0};
    }
    else if(c == 'R')
    {
        R {1,0};
    }
    else if(c == 'D')
    {
        R {0,-1};
    }
    R {0,1};
}


bool Solve(int x,int y,int Curx,int Cury,int i)
{
    if(i == s.sz)
    {
        R (Curx == 0 && Cury == 0);
    }

    pii To = Calc(s[i]);

    pii newPos = {Curx+To.fr,Cury+To.sc};
    if(newPos.fr == x && newPos.sc == y)
    {
        R Solve(x,y,Curx,Cury,i+1);
    }
    else
    {
        R Solve(x,y,newPos.fr,newPos.sc,i+1);
    }

}

int main()
{
    SPEED;
    Test
    {
        cin >> s;
        vector<pii> Cells;
        pii Cur = {0,0};
        for(int i=0;i<s.sz;i++)
        {
            pii Res = Calc(s[i]);
            Cur.fr += Res.fr;
            Cur.sc += Res.sc;
            if(Cur.fr == 0 && Cur.sc == 0)
            {
                continue;
            }
            Cells.pb(Cur);
        }
        bool Ok = false;
        for(int i=0;i<Cells.sz;i++)
        {
            if(Solve(Cells[i].fr,Cells[i].sc,0,0,0))
            {
                cout << Cells[i].fr << " " << Cells[i].sc << endl;
                Ok = true;
                break;
            }
        }
        if(!Ok)
        {
            cout << "0 0" << endl;
        }
    }
    R 0;
}
