#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <queue>
#include <string>
#include <set>
#include <unordered_set>
#include <time.h>
#include <random>
#define REP(i,N)for(long long i=0;i<(N);i++)
#define FOR(i,a,b)for(long long i=(a);i<=(b);i++)
#define FORD(i,a,b)for(long long i=a;i>=(b);i--)
#define ll long long
#define vi vector<ll>
#define vii vector<pair<ll,ll> >
#define vvi vector<vector<ll> >
#define vb vector<bool>
#define pii pair<ll,ll>
#define ALL(x) (x).begin(), (x).end()
#define SZ(a)((ll)(a).size())
#define CHECK_BIT(n,x)((bool)((n)&(((ll)1)<<(x))))
#define pow2(x) ((x)*(x))
#define VELA 1000999999999000000ll
#define X first
#define Y second
const ll mod = 1000000007ll;
#define DEBUG if(1)
#define DBG(x) DEBUG {cout<<#x<<" = "<<x<<"\n";}
#define DBGV(x) DEBUG {cout<<#x<<" = ["; REP(i,SZ(x)){cout<<x[i];if(i<SZ(x)-1)cout<<" , ";}cout<<"]\n";}
#include<stack>
using namespace std;

vii simulate(string mov, ll ox=-10000,ll oy=-10000) {
	ll x = 0;
	ll y = 0;
	vector<pii> pos;
	for (char c : mov) {
		ll nx = x;
		ll ny = y;
		if (c == 'U') {
			ny++;
		}
		else if (c == 'D') {
			ny--;
		}
		else if (c == 'R') {
			nx++;
		}
		else if (c == 'L') {
			nx--;
		}
		if (!(nx == ox && ny == oy)) {
			x = nx;
			y = ny;
		}
		pos.push_back({ x,y });
	}
	return pos;
}

int main() {
	cin.sync_with_stdio(0);
	ll ntests;
	cin >> ntests;
	REP(i, ntests) {
		string movement;
		cin >> movement;
		vii poss = simulate(movement);
		pii res = { 0,0 };
		for (pii pos : poss) {
			pii finpos=simulate(movement, pos.first, pos.second).back();
			if (finpos == pii(0,0)) {
				res = pos;
				break;
			}
		}
		cout << res.first << " " << res.second << "\n";
	}
	return 0;
}