#include <bits/stdc++.h>

using namespace std;

using ll = long long;
#define ar array


// ======== Idea ======== //


// ======== Implementation ======== //

void	UpdateCoord(char c, pair<int, int> &cur, const pair<int, int> &block) {
	switch (c) {
		case 'L' : 
			if (make_pair(cur.first - 1, cur.second) != block)
				cur.first -= 1;
			break;
		case 'R' : 
			if (make_pair(cur.first + 1, cur.second) != block)
				cur.first+=1;
			break;
		case 'U' : 
			if (make_pair(cur.first, cur.second + 1) != block)
				cur.second+=1;
		  break;
		case 'D' : 
			if (make_pair(cur.first, cur.second - 1) != block)
				cur.second-=1;
			break;
	}
}

void solve() {
	string s;
	cin >> s;
	int n = (int)s.size();
	vector<pair<int, int>> p(n);
	pair<int, int> prev = {0,0};
	for (int i = 0; i < n; ++i) {
		UpdateCoord(s[i], prev, {1e9 + 7, 1e9 + 7});
		p[i] = prev; 
	}
	for (int i = 0; i < n; ++i) {
		pair<int, int> cur = {0, 0};
		pair<int, int> ans = p[i];
		for (int j = 0; j < n; ++j) {
			UpdateCoord(s[j], cur, ans);
			//cerr << "current: " << cur.first << ' ' << cur.second << '\n';
		}
		if (cur == make_pair(0, 0)) {
			cout << ans.first << ' ' << ans.second << '\n';
			return ;
		}
	}
	cout << 0 << ' ' << 0 << '\n';
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	int T;
	cin >> T;
	while (T--) {
		solve();
	}
}

