/*-- ILSH  --*/
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef double ld;
#define pb push_back 
#define pop pop_back
#define mp make_pair
#define vii vector < ll >
#define dt cout<<"HERE\n";
#define pii pair < ll , ll >
#define vpi vector < pii >
#define fi first
#define se second 
#define sz(x) ((ll)x.size())
#define len(x) ((ll)x.length())
void up(vii &v){ for ( ll i=0;i<sz(v);i++) cout<<v[i]<<' '; cout<<'\n';}
const ll inf=1e18+1e17;
const ll mod =1e9+7;
using cd= complex < double > ;

//const ll mod = 998244353;
ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}  
ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return (res%mod);}
const ll N = 5e3 +5;
bool check(int fx, int fy, int pos, string &s, int x, int y){
	int n=len( s);
	for ( int i=pos;i<n;i++){
		int nx=x, ny=y;
		if ( s[i]=='R')
			nx=x+1;
		if ( s[i]=='L')
			nx=x-1;
		if ( s[i]=='U')
			ny=y+1;
		if ( s[i]=='D')
			ny=y-1;
		if ( nx==fx&&ny==fy)
			continue;
		else{
			x=nx;
			y=ny;
		}
	}
	if ( x==0&&y==0)
		return true;
	return false;
}
void solve(){
	map< pii , bool > m;

	string s;
	cin>> s;
	int n=len( s);
	int x_pos=0,y_pos=0;
	for ( int i=0;i<n;i++){
		int nx=x_pos, ny=y_pos;
		if ( s[i]=='R')
			nx=x_pos+1;
		if ( s[i]=='L')
			nx=x_pos-1;
		if ( s[i]=='U')
			ny=y_pos+1;
		if ( s[i]=='D')
			ny=y_pos-1;
		if ( m[{nx,ny}]==0){
			m[{nx, ny}]=1;
			if ( check( nx , ny,i,s, x_pos,y_pos)){
				cout<<nx<<' '<<ny<<'\n';
				return;
			}
		}
		x_pos=nx;
		y_pos=ny;
	}
	cout<<"0 0\n";


}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie( NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen ("INPUT.txt" , "r" , stdin);
		freopen ("OUTPUT.txt", "w" , stdout);
	#endif
	ll t=1;

	cin>>t;
	for ( ll i=1;i<=t;i++){
		//cout<<"Case "<<i<<": ";
    	solve();
    }
}