#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define sortall(a) sort(a.begin(),a.end())
#define X first
#define Y second
#define reall(a) reverse(a.begin(),a.end())
using namespace std;
const int maxn =105+3;
ll mod =1e9+7;
int xx[4] = { 0, 1, 0, -1 };
int yy[4] = { 1, 0, -1, 0 };
string step = "URDL";
ll Pow(ll a, ll b){ll res = 1;if(b <=0)return 1;while(b>0){if(b%2){res=(res%mod *a%mod);res%=mod;}a=(a%mod*a%mod)%mod;b/=2;}return res%mod;}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 //   freopen("herding.in","r",stdin);
   // freopen("herding.out","w",stdout);
    int t; cin >>t;
    while(t--){
        string s; cin>>s;
        vector<pair<int,int>>save(s.size());
        int x = 0;
        int y = 0;
        int n = s.size();
        bool ok = false;
        for(int i =0;i<n;i++){
            if(s[i] == 'L'){
                x--;
            }
            else if(s[i] == 'R'){
                x++;
            }
            else if(s[i] =='U'){
                y++;
            }
            else{
                y--;
            }
            save[i] = {x,y};
        }
        x = y = 0;
        for(int i = 0;i<n;i++){
            x = y= 0;
            for(int j =0;j<n;j++){
                if(s[j] == 'L'){
                    x--;
                }
                else if(s[j] == 'R'){
                    x++;
                }
                else if(s[j] =='U'){
                    y++;
                }
                else{
                    y--;
                }
                if(x == save[i].X and y == save[i].Y){
                    if(s[j] == 'L'){
                        x++;
                    }
                    else if(s[j] == 'R'){
                        x--;
                    }
                    else if(s[j] =='U'){
                        y--;
                    }
                    else{
                        y++;
                    }
                }
            }
            if(x == y and x ==0){
                cout<<save[i].X<<" "<<save[i].Y<<endl;
                ok = true;
                break;
            }
        }
        if(!ok)cout<<0<<" "<<0<<endl;
    }
}
