#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

bool check(string s,ll c1,ll c2){
    ll x=0,y=0;
    for(int i=0;i<s.size();i++){
        char c=s[i];
        if(c=='L'&&(x-1!=c1||y!=c2)){
            x--;
        }else if(c=='R'&&(x+1!=c1||y!=c2)){
            x++;
        }else if(c=='U'&&(x!=c1||y+1!=c2)){
            y++;
        }else if(c=='D'&&(x!=c1||y-1!=c2)){
            y--;
        }
    }
    return x==0&&y==0;
}

void solve(){
    string s;
    cin>>s;
    ll x=0,y=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='L'){
            x--;
        }else if(s[i]=='R'){
            x++;
        }else if(s[i]=='U'){
            y++;
        }else{
            y--;
        }
        if(check(s,x,y)){
            cout<<x<<" "<<y<<"\n";
            return;
        }
    }
    cout<<0<<" "<<0<<"\n";
}

int main(){
    FIO;
    ll t;
    cin>>t;
    while(t--){
        solve();
    }
}