/*########################################################################
# File Name: K.cpp
# Author: SoMnus_L
# Mail: lr599909928@gmail.com
# Created Time:六 12/26 14:04:13 2020
########################################################################*/
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
#define rep(a,b,c) for(int a=b;a<=c;++a)
#define per(a,b,c) for(int a=b;a>=c;--a)
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}

int t;
string s;

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

		int ex=0,ey=0;

		bool flag=false;
		int len=(int)s.size();

		rep(i,0,len-1){
			if(s[i]=='L') ex--;
			if(s[i]=='R') ex++;
			if(s[i]=='U') ey++;
			if(s[i]=='D') ey--;

			if(ex!=0 || ey!=0){
				int x=0,y=0;
				rep(j,0,len-1){
					if(s[j]=='L') x--;
					if(s[j]=='R') x++;
					if(s[j]=='U') y++;
					if(s[j]=='D') y--;

					if(x==ex && y==ey){
						if(s[j]=='L') x++;
						if(s[j]=='R') x--;
						if(s[j]=='U') y--;
						if(s[j]=='D') y++;
					}
				}
				if(x==0 && y==0){
					flag=true;
					cout<<ex<<' '<<ey<<'\n';
					break;
				}
			}
			if(flag) break;
		}

		if(!flag) cout<<"0 0\n";
	}


    return 0;
}
