#include <bits/stdc++.h>


using namespace std;


typedef long long ll;
#define MOD 1000000007
#define INF INT_MAX
#define rep(i,n) for(ll i=0;i<n;++i)

unordered_map<char,int> aa;
int dx[255],dy[255];
 

int main() {
    dx['L']=-1;
    dx['R']=1;
    dy['U']=1;
    dy['D']=-1;

    int t;
    cin>>t;

    while(t--){
        string s;
        cin>>s;
        bool f =0;
        int sx =0,sy=0;
        for(int i=0;i<s.size();i++){
            sx += dx[s[i]];
            sy += dy[s[i]];

            if(sy == 0 && sx ==0) continue;

            int x =0,y=0;
            for(int j=0;j<s.size();j++){
                x += dx[s[j]];
                y += dy[s[j]];
                if(x ==sx && y ==sy){
                    x -= dx[s[j]];
                    y -= dy[s[j]];
                }
            }

            if(x ==0 & y ==0){
                f = 1;
                cout<<sx<<" "<<sy<<endl;
                break;
            }

        }
        if(!f) cout<<"0 0"<<endl;
    }

}