#include <bits/stdc++.h>
using namespace std;

void f(char op, int x, int y, vector<int>& evolved_cord){
    evolved_cord[0] = x;
    evolved_cord[1] = y;
    if(op=='R')
        evolved_cord[0] = x+1;
    else if(op=='L')
        evolved_cord[0] = x-1;
    else if(op=='U')
        evolved_cord[1] = y+1;
    else if(op=='D')
        evolved_cord[1] = y-1;    
}

int main(){
    int t; cin >> t;
    while(t--){
        string s; cin>>s;
        int n = s.size();
        vector<int> original_x(n);
        vector<int> original_y(n);
        int x=0,y=0;
        for(int i=0; i<n; i++){
            vector<int> evolved_cord(2);
            f(s[i], x,y, evolved_cord);
            x = evolved_cord[0];
            y = evolved_cord[1];
            original_x[i] = evolved_cord[0];
            original_y[i] = evolved_cord[1];
        }

        // for(int i=0; i<n; i++){
        //     cout << original_x[i] << ' ' << original_y[i] << endl;
        // }

        int ans_x=0, ans_y=0;
        for(int i=0; i<n; i++){
            // cout << "obstacle at index " << i << endl;
            x=0;y=0;
            for(int j=0; j<n; j++){
                vector<int> evolved_cord(2);
                f(s[j], x,y, evolved_cord);
                if(!(evolved_cord[0]==original_x[i] && evolved_cord[1]==original_y[i])){
                    x = evolved_cord[0];
                    y = evolved_cord[1];
                }
                // cout << x << ' ' << y << endl;
            }
            if(x==0 && y==0){
                ans_x=original_x[i];
                ans_y=original_y[i];
                break;
            }
        }
        cout << ans_x << ' ' << ans_y << endl;
    }
    return 0;
}