#include<bits/stdc++.h>
#define MAX 1000000007
#define MOD 998244353
#define ll long long int
#define fo(i,a,n) for(int i=a;i<n;i++)
#define ull unsigned long long int
#define pb push_back
#define eb emplace_back
#define in insert
#define cl clear
#define ld long double
#define mp make_pair
#define ii pair<int,int>
const ll inf = 10e16+7;
using namespace std;
typedef vector<vector<int>> vvi;

void print(int arr[], int n){
    fo(i,0,n){
        cout<<arr[i]<<" "; 
    }
    cout<<endl;
}

int main(){
    // fast i/o
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    map<char, int> dx,dy;
    dx.insert({'R',1});
    dy.insert({'R',0});
    dx.insert({'L',-1});
    dy.insert({'L',0});
    dy.insert({'U',1});
    dx.insert({'U',0});
    dy.insert({'D',-1});
    dx.insert({'D',0});

    int t;
    cin>>t;
    while(t--){

        string s;
        cin>>s;

        vector<pair<int,int>> v(s.length());
        int a=0,b=0;

        fo(i,0,s.length()){
            if(s[i]=='R'){
                a+=1;
                v[i] = {a,b};
            }
            else if(s[i]=='L'){
                a-=1;
                v[i] = {a,b};
            }
            else if(s[i]=='D'){
                b-=1;
                v[i] = {a,b};
            }
            else {
                b+=1;
                v[i] = {a,b};
            }
        }

        bool flg=0;
        fo(i,0,s.length()){

            a=0;b=0;

            fo(j,0,s.length()){
                if(a+dx[s[j]]==v[i].first && b+dy[s[j]]==v[i].second){
                    continue;
                }
                if(s[j]=='R'){
                    a+=1;
                }
                else if(s[j]=='L'){
                    a-=1;
                }
                else if(s[j]=='D'){
                    b-=1;
                }
                else {
                    b+=1;
                }
            }

            if(a==0 && b==0){
                flg=1;
                cout<<v[i].first<<" "<<v[i].second<<endl;
                break;
            }
        }

        if(!flg){
            cout<<0<<" "<<0<<endl;
        }

    }

    return 0;
}