#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define maxn 100007
#define ll long long 
#define br '\n'
#define pb push_back
#define mod1 1000000007
#define mod 998244353
#define INF  0x3f3f3f3f
#define limit 1e18
 

pair<int,int> foo(pair<int,int>a,char x)
{
	if(x=='L')
	{
		a.first-=1;
	}
	else if(x=='R')
	{
		a.first+=1;
	}
	else if(x=='U')
	{
		a.second+=1;
	}
	else
	{
		a.second-=1;
	}
	return a;
}

void solve()
{
	string s;
	cin>>s;
	int n=s.length();
	pair<int,int>ans,x,y,z;
	y={0,0};
	ans={0,0};
	for(int i=0;i<n;i++)
	{
		y=foo(y,s[i]);
		x={0,0};
		for(int j=0;j<n;j++)
		{
			

			z=foo(x,s[j]);

			if(z==y)
			{
				continue;
			}
			else
			{
				x=z;
			}

		}
		if(x.second==0 && x.first==0)
		{
			ans=y;
			break;
		}
		//cout<<i<<" "<<x.first<<" "<<x.second<<br;
	}
	cout<<ans.first<<" "<<ans.second<<br;


}


 int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
}
