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

# define ll long long int
# define pb push_back
# define in insert
# define endl '\n'

void TC()
{
   string s;
   cin >> s;
   int n = s.size();
   int idx = -1;
   for (int i = 0;i<n;i++){
    int idxX=0,idxY=0;
    ll tempx = -1e9+1,tempy = -1e9+1;
    for(int j=0;j<=i;j++){
        if(s[j] == 'U'){
          ++idxY;
        }
        if(s[j] == 'D'){
          --idxY;
        }
        if(s[j] == 'L'){
          --idxX;
        }
        if(s[j] == 'R'){
          ++idxX;
        }
    }
    tempx = idxX;
    tempy = idxY;
    idxX = 0;
    idxY = 0;
    for(int j=0;j<n;j++){
      int stateX = 0;
      int stateY = 0;
      if(s[j] == 'U'){
          ++stateY;
      }
      else if(s[j] == 'D'){
        --stateY;
      }
      else if(s[j] == 'L'){
        --stateX;
      }
      else if(s[j] == 'R'){
        ++stateX;
      }
      
      if(tempx != stateX+idxX || tempy != stateY+idxY){
        idxX += stateX;
        idxY += stateY;
      }
    }
    if(idxX == 0 && idxY == 0){
      idx = i;
      break;
    }
    
   }
   if(idx == -1) cout << "0 0"<<endl;
   else {
    int idxX=0,idxY=0;
    for(int i=0;i<=idx ;i++){
        if(s[i] == 'U'){
          ++idxY;
        }
        if(s[i] == 'D'){
          --idxY;
        }
        if(s[i] == 'L'){
          --idxX;
        }
        if(s[i] == 'R'){
          ++idxX;
        }
    }
    cout << idxX << " " <<idxY <<endl;
   }   
  
  
  

}
int main()
{   ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int tc = 1;
    cin >> tc;
    while(tc--){
        TC();
    }
}